当我们使用 new ModelMapper类型转换遇到相似字段时编译器就会无法识别字段。
ProductOrderChangesItemDTO itemDTO = new ModelMapper()
.map(iit, ProductOrderChangesItemDTO.class);
会抛出如下异常:
此时只需要给modelMapper 设置如下参数即可,此时就可以了
ModelMapper modelMapper = new ModelMapper();
//完全匹配字段
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
ProductOrderChangesItemDTO itemDTO = new ModelMapper()
.map(iit, ProductOrderChangesItemDTO.class);