我想排除所有'createdDate'字段在我的所有映射字段中反序列化:
与此类似:
hash_hmac()
因此,在查询时可以看到该字段但不可更新。
有没有办法在全局范围内执行此操作而无需在每个映射上指定它?
答案 0 :(得分:0)
将所有公共字段移至源类和目标类的超类。并为超类创建映射。完整的示例可以在Dozer fields - Global Exclude Example
找到第1步:来源POJO:
//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>