728x90
반응형
mapping 어노테이션
-
MapStruct 의 @Mapping 사용 방법을 알아보자!Server/Spring Boot 2025. 4. 16. 11:38
🎯 @Mapping 어노테이션 사용 예제@Mapping은 DTO와 Entity 간에 필드명이 다를 때나 특정 필드 매핑을 제어하고 싶을 때 사용합니다.예시 1️⃣: 필드명이 다를 경우// User 엔티티public class User { private Long id; private String name;}// UserDtopublic class UserDto { private Long id; private String username; // 엔티티에서는 'name'}@Mapper(componentModel = "spring")public interface UserMapper { @Mapping(source = "name", target = "username") UserD..