我是Dozer
的新手,我刚学会使用Dozer将一个源对象映射到目标。我必须根据条件将源转换为目标。但是,如何将源中的一个字段作为另一个字段映射到多个目标?
Dozer
中有什么可能吗?(如果不是Dozer
,则其他任何内容都支持此内容)
源类
class Employee{
@Mapping("cId") //==> this works only for Contractor mapping
private Integer eId;
@Mapping("managerName") //==> this works only for Manager mapping
private String eName;
private boolean isManager;
// set&get methods
}
destination1 class
class Contractor{
private Integer cId;
private String cName;
// set&get methods
}
destination2 class
class Manager{
private Integer managerId;
private String managerName;
// set&get methods
}
映射
Contractor contractor = new DozerBeanMapper().map(employee, Contractor.class);
Manager manager = new DozerBeanMapper().map(employee, Manager.class);