묻고 답해요
131만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결스프링 시큐리티
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; } //...// } 참고하세용^^
-
미해결Spring Cloud로 개발하는 마이크로서비스 애플리케이션(MSA)
BeanUtils .copyProperties VS ModelMapper 질문입니다
안녕하세요 강사님지난 강의부터 쭉 들어왔었는데요, 모델메퍼를 고르신 이유가 궁금합니다.단순히 값 매핑 객체 생성을 위해서는 Spring 제공 BeanUtils 을 사용해도 되지만,3rd party 인 ModelMapper 사용을 고려하신 이유가 궁금합니다. `값 복제`, `인스턴스 생성` 외에도 어떤 매리트가 있을까요? 감사합니다