简体   繁体   English

条件推土机xml映射

[英]Conditional dozer xml mapping

In an object, i have two properties A and B. I want to map these properties based on condition to the target property T. I'm using xml based dozer mapping - 在一个对象中,我有两个属性A和B。我想根据条件将这些属性映射到目标属性T。我正在使用基于xml的推土机映射-

if(A != null)
  <field>
        <a>A</a>
        <b>T</b>
    </field>
else if (B != null)
   <field>
        <a>B</a>
        <b>T</b>
    </field>

How to achieve this in xml ? 如何在xml中实现呢?

If A and B are the only mapped properties and A and B can't be not null at the same time you can try to exclude mapping of null values: 如果A和B是唯一的映射属性,并且A和B不能同时为非null,则可以尝试排除null值的映射:

<mapping map-null="false">
    <class-a>SrcClass</class-a>
    <class-b>DestClass</class-b>
    <field>
       <a>A</a>
       <b>T</b>
    </field>   
    <field>
       <a>B</a>
       <b>T</b>
    </field>
</mapping>

See also Exclude Mapping Null Values 另请参见排除映射空值

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

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