Framework/Spring Boot
ModelMapper 수동으로 필드명 매핑 설정
잔망루피
2022. 9. 12. 12:38
@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/
반응형