我的应用程序中有以下类映射。
public class Source {
// Header
private String one;
private String two;
// Body
private String three;
private String four;
private String five;
private String six;
// Getters & Setters
}
public class Destination {
private Header header;
private Body body;
// Getter & Setter
}
public class Header {
private String one;
private String two;
// Getter & Setters
}
public class Body {
private String three;
private String four;
private String five;
private String six;
// Getter & Setters
}
我必须使用Dozer从源bean转换为目标bean。这个用例可能吗?我知道Dozer默认具有双向映射,我们可以单向映射。但是,与简单的java代码相比,写一个单向特定映射xml是值得的,将数据从一个bean复制到另一个bean?请建议。
答案 0 :(得分:0)
映射XML
DECLARE mlat FLOAT(10,6) DEFAULT 0.00084;
<强>用法强>
<?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 map-id="k" type="one-way">
<class-a>com.test.pah.Source</class-a>
<class-b>com.test.pah.Destination</class-b>
<field>
<a>one</a>
<b>header.one</b>
</field>
<field>
<a>two</a>
<b>header.two</b>
</field>
<field>
<a>three</a>
<b>body.three</b>
</field>
<field>
<a>four</a>
<b>body.four</b>
</field>
<field>
<a>five</a>
<b>body.five</b>
</field>
<field>
<a>six</a>
<b>body.six</b>
</field>
</mapping>
</mappings>
更多 http://dozer.sourceforge.net/documentation/deepmapping.html