ModelMapper skip a field

后端 未结 3 1341
旧巷少年郎
旧巷少年郎 2020-12-30 06:54

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

3条回答
  •  难免孤独
    2020-12-30 07:13

    For the configuration to work need to add:

    modelMapper.getConfiguration().setAmbiguityIgnored(true);

    E.g.

    ModelMapper modelMapper = new ModelMapper();
    modelMapper.getConfiguration().setAmbiguityIgnored(true);
    modelMapper.addMappings(clientPropertyMap);
    modelMapper.map(UserDTO, User);
    
    
    PropertyMap clientPropertyMap = new PropertyMap() {
        @Override
        protected void configure() {
            skip(destination.getCity());
        }
    };
    

提交回复
热议问题