// <https://mvnrepository.com/artifact/org.modelmapper/modelmapper>
implementation 'org.modelmapper:modelmapper:3.1.1'
- 콩을 등록하는 설정용 클래스로 매번 객체를 생성하지 않게 만듬
**@Configuration**
public class AppConfig {
/* 설명. 미리 dependency로 추가해 둘 것 */
/* 설명. DTO <-> Entity 매핑을 위한
* ModelMapper 라이브러리 bean 추가 */
**@Bean
public ModelMapper modelMapper(){
return new ModelMapper();
}** // 객체를 매번 새로 생성해야되서 미리 만들어 놓음
}
**private final ModelMapper modelMapper;**
@Autowired
public MenuService(MenuRepository menuRepository,
ModelMapper modelMapper) {
this.menuRepository = menuRepository;
**this.modelMapper = modelMapper;**
}
...// 메서드 핸들러 내부 리턴
**return modelMapper.map(menu, MenuDTO.class);**