2016-06-21 49 views
0

我想從我所有的映射的字段被反序列排除所有「createdDate」字段:推土機:是否可以單向排除所有映射類上的字段?

與此類似:

<field-exclude type="one-way""> <a>createdDate</a> <b>createdDate</b> </field-exclude>

因此,查詢但不能當具有現場可見更新。

有沒有辦法在全球範圍內做到這一點,而無需在每個映射上指定它?

回答

0

將所有常用字段移到源類和目標類上的超類。並創建超類的映射。源的POJO:完整的例子可以在Dozer fields - Global Exclude Example

步驟1中找到

//PersonType.java 
public class AddressType extends BaseType{ 

    private String addrLine1; 
    private String city; 
    private String state; 
    private int zipCode; 
    // Setter and Getter methods are removed 
} 
// BaseType.java 
public class BaseType { 
     private String createdDate; 
    // Setter and Getter methods are removed 
} 

步驟2:目標的POJO:

// Address.java 
public class Address extends BaseDomain{ 

    private String addrLine1; 
    private String city; 
    private String state; 
    private int zip5; 
// Setter and Getter methods are removed 
} 
//BaseDomain.java 
public class BaseDomain { 
    private String createdDate; 
// Setter and Getter methods are removed 
} 

步驟3:創建映射

<?xml version="1.0" encoding="UTF-8"?> 
<mappings xmlns="http://dozer.sourceforge.net" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://dozer.sourceforge.net 
      http://dozer.sourceforge.net/schema/beanmapping.xsd"> 
    <mapping> 
      <class-a>com.codesimplify.dozersamples.fieldexclude.AddressType</class-a> 
      <class-b>com.codesimplify.dozersamples.fieldexclude.Address</class-b> 
    </mapping> 

    <mapping> 
    <class-a>com.codesimplify.dozersamples.fieldexclude.BaseType</class-a> 
    <class-b>com.codesimplify.dozersamples.fieldexclude.BaseDomain</class-b> 
    <field-exclude type="one-way"> 
     <a>createdDate</a> 
     <b>createdDate</b> 
    </field-exclude>  
    </mapping> 
</mappings>