Open berryberrybin opened 1 year ago
// 수정 전 Mapper 코드
@Mapper(
componentModel = "spring",
injectionStrategy = InjectionStrategy.CONSTRUCTOR,
unmappedTargetPolicy = ReportingPolicy.ERROR
)
public interface CommentMapper {
@Mapping(target = "description", source = "commentCommand.description")
@Mapping(target = "commentId", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "updatedAt", ignore = true)
@Mapping(target = "isDeleted", constant = "false")
Comment toComment(User user, Post post, Set<CommentLike> commentLikes, CommentCommand commentCommand);
CommentInfo toCommentInfo(Comment comment, String nickname, Boolean isLiked, Integer likeCount);
}
기본적으로는 인터페이스에 @Mapper를 붙이면 됨
MapStruct에서는 UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); 같은 방식으로 Mapper Bean을 만드는 것을 권장함
@Mapper(componentModel = "spring")과 @Autowired를 이용하여 만들 수도 있습니다.