无法将源类到目标类的深度映射映射SourceEmployee.Address.houseName
到TargetEmployee.houseName
源对象类
public class SourceEmployee
{
private String empName;
private Address addr;
enter code here
@Mapping("empName")
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Address getAddr() {
return addr;
}
public void setAddr(Address addr) {
this.addr = addr;
}
}
地址类
public class Address
{
private String houseName;
public String getHouseName() {
return houseName;
}
public void setHouseName(String houseName) {
this.houseName = houseName;
}
}
目标对象
public class TargetEmployee
{
private String empName;
private String houseName;
public String getHouseName() {
return houseName;
}
public void setHouseName(String houseName) {
this.houseName = houseName;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
主类从源复制到目标
public class CopyAttributes
{
public static void main(String args[])
{
SourceEmployee sourceEmp = new SourceEmployee();
sourceEmp.setEmpName("Rafi");
Address adr = new Address();
adr.setHouseName("Aashiyana");
sourceEmp.setAddr(adr);
Mapper mapper = new DozerBeanMapper();
TargetEmployee destObject = mapper.map(sourceEmp, TargetEmployee.class);
System.out.println(destObject.getEmpName());
System.out.println(destObject.getHouseName());
}
}