我需要使用推土机框架将 A 类映射到 C 类。
public class A {
private String fielda1;
private String fielda2;
public String getFielda1() {
return fielda1;
}
public void setFielda1(String fielda1) {
this.fielda1 = fielda1;
}
public String getFielda2() {
return fielda2;
}
public void setFielda2(String fielda2) {
this.fielda2 = fielda2;
}
}
public class B {
private List<C> cList;
public List<C> getcList() {
return cList;
}
public void setcList(List<C> cList) {
this.cList = cList;
}
public static class C {
private String fieldc1;
private String fieldc2;
public String getFieldc1() {
return fieldc1;
}
public void setFieldc1(String fieldc1) {
this.fieldc1 = fieldc1;
}
public String getFieldc2() {
return fieldc2;
}
public void setFieldc2(String fieldc2) {
this.fieldc2 = fieldc2;
}
}
}
XML 映射文件:
<mapping wildcard="false" map-null="false" map-id="test">
<class-a>test.A</class-a>
<class-b>test.B.C</class-b>
<field>
<a>fielda1</a>
<b>fieldc1</b>
</field>
<field>
<a>fielda1</a>
<b>fieldc2</b>
</field>
</mapping>
当我尝试映射这些类时,出现以下异常:
org.dozer.MappingException: java.lang.ClassNotFoundException: test.B.C
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:33)
它表明推土机无法处理这种情况并使用 B 类作为包名。可以使用自定义转换器解决此问题。我只是想知道是否有任何技巧可用于仅使用 XML 配置来转换这些类?