ModelMapper skip a field

萝らか妹 提交于 2019-12-07 03:50:39

问题


I would like to map between UserDTO and User, but excluding one field, say city. How can I do that, cause I though that this approach would work, but it doesn't:

ModelMapper modelMapper = new ModelMapper();

modelMapper.typeMap(UserDTO.class,User.class).addMappings(mp -> {
    mp.skip(User::setCity);
});

回答1:


Because of the generic parameters, we couldn't use the lambda expression.

ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Dto, Source>() {
                @Override
                protected void configure() {
                    skip(destination.getBlessedField());
                }
            });


来源:https://stackoverflow.com/questions/49074784/modelmapper-skip-a-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!