From 8c5d7c6c3fa88639cb05885e3bd4a2c5024e21d4 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 27 Aug 2025 09:42:10 +0900 Subject: [PATCH] =?UTF-8?q?[=EB=A7=A4=ED=8D=BC=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20CommonCodeMapper,=20CommonGroupCodeMapper?= =?UTF-8?q?,=20MemberMapper=EC=97=90=EC=84=9C=20componentModel=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20GlobalMapperConfig=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=98=EC=97=AC=20=EB=A7=A4=ED=8D=BC=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=ED=86=B5=EC=9D=BC=ED=95=98=EA=B3=A0,=20Gl?= =?UTF-8?q?obalMapperConfig=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20?= =?UTF-8?q?=EC=83=88=EB=A1=9C=20=EC=B6=94=EA=B0=80=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EB=A7=A4=ED=95=91=20=EC=A0=84=EB=9E=B5=EC=9D=84=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common_code/mapper/CommonCodeMapper.java | 3 ++- .../mapper/CommonGroupCodeMapper.java | 3 ++- .../base/member/mapper/MemberMapper.java | 5 ++--- .../global/config/GlobalMapperConfig.java | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java index 373889b..801aff2 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonCodeMapper.java @@ -6,12 +6,13 @@ import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeResponse import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonCodeRequestDto; import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface CommonCodeMapper { /** diff --git a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java index e5f7f89..9358fd4 100644 --- a/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/admin/common_code/mapper/CommonGroupCodeMapper.java @@ -6,12 +6,13 @@ import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonGroupCodeRes import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonGroupCodeRequestDto; import com.bio.bio_backend.domain.admin.common_code.entity.CommonGroupCode; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface CommonGroupCodeMapper { /** diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java index 73f3020..f5468d7 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java @@ -5,16 +5,15 @@ import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto; import com.bio.bio_backend.domain.base.member.dto.MemberDto; import com.bio.bio_backend.domain.base.member.entity.Member; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; +import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; -@Mapper(componentModel = "spring") +@Mapper(config = GlobalMapperConfig.class) public interface MemberMapper { - MemberMapper INSTANCE = Mappers.getMapper(MemberMapper.class); - /** * CreateMemberRequestDto를 MemberDto로 변환 * 기본값 설정: role = MemberRole.MEMBER, useFlag = true diff --git a/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java b/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java new file mode 100644 index 0000000..453a1da --- /dev/null +++ b/src/main/java/com/bio/bio_backend/global/config/GlobalMapperConfig.java @@ -0,0 +1,21 @@ +package com.bio.bio_backend.global.config; + +import org.mapstruct.*; + +@MapperConfig( + componentModel = "spring", + + // null 값은 매핑하지 않음 (부분 업데이트) + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, + + // NPE 방지용 null 체크 + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + + // 매핑 누락 시 컴파일 오류 + unmappedTargetPolicy = ReportingPolicy.ERROR, + + // 컬렉션 매핑 전략 + collectionMappingStrategy = CollectionMappingStrategy.ACCESSOR_ONLY +) +public interface GlobalMapperConfig { +}