This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.fixmapstructobjectnullproblem.entity; | |
import Lombok.Data; | |
@Data | |
public class User { | |
String username = "werterzz"; | |
String password = "password"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.fixmapstructobjectnullproblem.dto; | |
import lombok.Data; | |
@Data | |
public class UserDto { | |
String username; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.fixmapstructobjectnullproblem.mapper; | |
import com.example.fixmapstructobjectnullproblem.dto.UserDto; | |
import com.example.fixmapstructobjectnullproblem.entity.User; | |
import org.mapstruct.Mapper; | |
@Mapper(componentModel = "spring") | |
public interface UserMapper { | |
UserDto toUserDto(User user); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.fixmapstructobjectnullproblem; | |
import com.example.fixmapstructobjectnullproblem.dto.UserDto; | |
import com.example.fixmapstructobjectnullproblem.entity.User; | |
import com.example.fixmapstructobjectnullproblem.mapper.UserMapper; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.mapstruct</groupId> | |
<artifactId>mapstruct</artifactId> | |
<version>${org.mapstruct.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.mapstruct</groupId> | |
<artifactId>mapstruct-processor</artifactId> | |
<version>${org.mapstruct.version}</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.projectlombok</groupId> | |
<artifactId>lombok</artifactId> | |
<optional>true</optional> | |
</dependency> | |
<dependency> | |
<groupId>org.mapstruct</groupId> | |
<artifactId>mapstruct</artifactId> | |
<version>${org.mapstruct.version}</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> fruits = Arrays.asList("orange", "apple", "banana", "cherry", "pear", "mango"); | |
System.out.println("before map: " + fruits); | |
fruits = fruits.stream().map(fruit -> fruit.toUpperCase()).collect(Collectors.toList()); | |
System.out.println("after map: " + fruits); | |
// output | |
// before map: [orange, apple, banana, cherry, pear, mango] | |
// after map: [ORANGE, APPLE, BANANA, CHERRY, PEAR, MANGO] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> fruits = Arrays.asList("orange", "apple", "banana", "cherry", "pear", "mango"); | |
System.out.println("before filter: " + fruits); | |
fruits = fruits.stream().filter(fruit -> fruit.contains("e")).collect(Collectors.toList()); | |
System.out.println("after filter: " + fruits); | |
// output | |
// before filter: [orange, apple, banana, cherry, pear, mango] | |
// after filter: [orange, apple, cherry, pear] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> fruits = Arrays.asList("orange", "apple", "banana", "cherry", "pear", "mango"); | |
System.out.println("before sorted: " + fruits); | |
fruits = fruits.stream().sorted().collect(Collectors.toList()); | |
System.out.println("after sorted: " + fruits); | |
// output | |
// before sorted: [orange, apple, banana, cherry, pear, mango] | |
// after sorted: [apple, banana, cherry, mango, orange, pear] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> fruits = Arrays.asList("orange", "apple", "banana", "cherry", "pear", "mango"); | |
fruits.stream().map(fruit -> fruit.toUpperCase()).forEach(fruit -> System.out.println(fruit)); | |
// output | |
// ORANGE | |
// APPLE | |
// BANANA | |
// CHERRY | |
// PEAR | |
// MANGO |
OlderNewer