Tag: modelmapper

如果从Modelmapper中为null,则如何排除整个属性

ModelMapper( http://modelmapper.org/ )是否支持排除属性的内容? 如果该值为null。 我刚刚找到了PropertyMap。 但这对我来说是一个制约因素。 因为我必须描述我想要的特定属性。 像这样。 ModelMapper modelMapper = new ModelMapper(); modelMapper.addMappings(new PropertyMap() { @Override protected void configure() { when(Conditions.isNull()).skip().setName(source.getName()); when(Conditions.isNull()).skip().set…(source.get…()); when(Conditions.isNull()).skip().set…(source.get…()); when(Conditions.isNull()).skip().set…(source.get…()); when(Conditions.isNull()).skip().set…(source.get…()); when(Conditions.isNull()).skip().set…(source.get…()); } }); 在我的情况下,我有很多财产和冗长。 如果映射属性为all,则如何排除它们。 有更舒适的解决方案吗? 谢谢。

ModelMapper:确保该方法的参数为零,并且不返回void

我为模型映射器配置了以下配置,以将User类的实例转换为ExtendedGetUserDto的实例。 public ExtendedGetUserDto convertToExtendedDto(User user) { PropertyMap userMap = new PropertyMap() { protected void configure() { map().setDescription(source.getDescription()); map().setId(source.getId()); // map().setReceivedExpenses( // source.getReceivedExpenses() // .stream() // .map(expense -> expenseDtoConverter.convertToDto(expense)) // .collect(Collectors.toSet()) // ); Set result = new HashSet(); for (Invitation inv: source.getReceivedInvitations()) { System.out.println(“HELLO”); //result.add(null); } //map().setReceivedInvitations(result); } }; modelMapper.addMappings(userMap); return modelMapper.map(user, ExtendedGetUserDto.class); } 在注释掉setReceivedExpense之前我收到了这个错误: org.modelmapper.ConfigurationException: […]