繁体   English   中英

推土机:是否可以在所有映射的类中单向排除字段?

[英]Dozer: Is it possible to one-way exclude a field on all mapped classes?

我想从所有映射字段上反序列化的过程中排除所有“ createdDate”字段:

与此类似:

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

因此,查询时该字段可见,但不可更新。

有没有一种全局方法可以不必在每个映射上都指定它?

将所有公共字段移至源类和目标类的超类。 并为超级类创建映射。 完整示例可在推土机字段中找到-全局排除示例

步骤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>

暂无
暂无

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

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