简体   繁体   English

推土机映射到现有对象非空字段

[英]Dozer map to existing object non null fields

How can I map one object to another (existing) excluding null fields? 如何将一个对象映射到另一个(现有)排除空字段的对象?

For example: 例如:

class A {
    String a1;
    String a2;
}

class B {
    String a1;
    String a2;
}

In A object I have non null field a1, on B object I have non null field a2. 在A对象中,我具有非null字段a1,在B对象中,我具有非null字段a2。 Is there any way to map object A to object B exclude field a2? 有什么方法可以将对象A映射到对象B的排除字段a2? Without custom converter and without excluding this field in mapping.xml? 没有自定义转换器并且没有在mapping.xml中排除此字段?

You should use map-null attribute on <mapping> element in your dozer-configuration-mapping.xml file: 您应该在dozer-configuration-mapping.xml文件的<mapping>元素上使用map-null属性:

<mapping map-null="false">
  <class-a>your.package.A</class-a>
  <class-b>your.package.B</class-b>    
</mapping>   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM