@Configuration
@RequiredArgsConstructor
public class CustomModelMapper {
private final ModelMapper modelMapper;
@Bean
public ModelMapper standardMapper(){
modelMapper.getConfiguration()
.setMatchingStrategy(MatchingStrategies.STANDARD);
modelMapper.createTypeMap(Post.class, PostResponseDto.class)
.addMapping(Post :: getId, PostResponseDto :: setPostId)
.addMapping(Post :: getTitle, PostResponseDto :: setPostTitle)
.addMapping(Post :: getContent, PostResponseDto :: setPostContent);
return modelMapper;
}
}
addMapping()으로 매핑을 해주었다.
참고 👇
http://modelmapper.org/user-manual/property-mapping/
반응형
'Framework > Spring Boot' 카테고리의 다른 글
ModelMapper Matching Strategy 정리 (0) | 2022.10.05 |
---|---|
[Spring Security] rememberMe 설정 (0) | 2022.09.19 |
[Error] Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported (0) | 2022.09.07 |
업로드 파일 사이즈 (0) | 2022.08.16 |
[Error] Could not write JSON: Java 8 date/time type `java.time.LocalDateTime` not supported by default: (0) | 2022.07.16 |