如果从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配置为忽略所有null属性:

 modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull()); 

例如,对于目标对象的部分更新很有用,在目标对象中,您只想从源对象复制非空的那些属性。