inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

Entity에 setter 사용 안할시 ModelMapper 설정

미해결

스프링 시큐리티

수강생분들에게 정보 공유해드리고 싶어서 게시판에 글 남깁니다. ModelMapper 를 사용하면 객체에서 객체로 쉽게 변환할 수 있습니다. 그런데 Setter 를 사용하지 않은 Entity 또는 객체 에서 Dto 로 변환할 매핑되지 않는 문제가 발생합니다. 이를 해결하기 위해서 ModelMapper modelMapper = new ModelMapper(); modelMapper.getConfiguration() .setFieldAccessLevel(Configuration.AccessLevel.PRIVATE) .setFieldMatchingEnabled(true); 위와 같이 설정한뒤 사용하면 됩니다.^^ 저는 @Bean public ModelMapper modelMapper() { ModelMapper modelMapper = new ModelMapper(); modelMapper.getConfiguration() .setFieldAccessLevel(Configuration.AccessLevel.PRIVATE) .setFieldMatchingEnabled(true); return modelMapper; } 빈으로 등록해서 사용했습니다.ㅎㅎ InheritingConfiguration 클래스에서 ModelMapper 기본 fieldAccessLevel 이 fieldAccessLevel = AccessLevel.PUBLIC; 임을 확인 할 수 있습니다.^^ public class InheritingConfiguration implements Configuration { //...// /** * Creates an initial InheritingConfiguration. */ public InheritingConfiguration() { parent = null; typeMapStore = new TypeMapStore(this); converterStore = new ConverterStore(); valueAccessStore = new ValueAccessStore(); valueMutateStore = new ValueMutateStore(); sourceNameTokenizer = NameTokenizers.CAMEL_CASE; destinationNameTokenizer = NameTokenizers.CAMEL_CASE; sourceNamingConvention = NamingConventions.JAVABEANS_ACCESSOR; destinationNamingConvention = NamingConventions.JAVABEANS_MUTATOR; sourceNameTransformer = NameTransformers.JAVABEANS_ACCESSOR; destinationNameTransformer = NameTransformers.JAVABEANS_MUTATOR; matchingStrategy = MatchingStrategies.STANDARD; fieldAccessLevel = AccessLevel.PUBLIC; methodAccessLevel = AccessLevel.PUBLIC; fieldMatchingEnabled = Boolean.FALSE; ambiguityIgnored = Boolean.FALSE; fullTypeMatchingRequired = Boolean.FALSE; implicitMatchingEnabled = Boolean.TRUE; preferNestedProperties = Boolean.TRUE; skipNullEnabled = Boolean.FALSE; useOSGiClassLoaderBridging = Boolean.FALSE; collectionsMergeEnabled = Boolean.FALSE; } //...// } 참고하세용^^

  • modelmapper
  • spring-boot
  • without
  • java
  • setter
  • setter없이
  • Spring Security
개발하는쿼카 댓글 1 좋아요 3 조회수 1064

인기 태그

인프런 TOP Writers

주간 인기글