將model層中的Java bean轉化成VO層(又叫DTO層)的Java bean的這個過程,有沒有工具自動協做咱們完成?java
使用Model Mapper進行處理。spring
ext{ modelmapperVersion = '2.3.5' } dependencies{ implementation group: 'org.modelmapper', name: 'modelmapper', version: modelmapperVersion }
@Bean public ModelMapper modelMapper() { return new ModelMapper(); }
注入Model Mapper:app
@Resource private ModelMapper modelMapper;
使用mapper:工具
MyModel myModel = modelMapper.map(myVO, MyModel.class);