Mapping 推土机-使用自定义创建方法
我不确定我是否正确理解推土机映射器中的自定义创建方法。我需要将int类型的bean属性转换为TransTypeCodebook对象实例。但我得到了:Mapping 推土机-使用自定义创建方法,mapping,dozer,Mapping,Dozer,我不确定我是否正确理解推土机映射器中的自定义创建方法。我需要将int类型的bean属性转换为TransTypeCodebook对象实例。但我得到了: 2013-09-13 15:47:27,009 [main] ERROR org.dozer.MappingProcessor - Field mapping error --> MapId: null Type: null Source parent class: cz.jaksky.dozer.a.HolderA Source f
2013-09-13 15:47:27,009 [main] ERROR org.dozer.MappingProcessor - Field mapping error -->
MapId: null
Type: null
Source parent class: cz.jaksky.dozer.a.HolderA
Source field name: transType
Source field type: class java.lang.Integer
Source field value: 0
Dest parent class: cz.jaksky.dozer.b.HolderB
Dest field name: transTypeCodebook
Dest field type: cz.jaksky.dozer.b.codebook.TransTypeCodebook
org.dozer.MappingException: Illegal object type for the method 'setTransTypeCodebook'.
Expected types:
cz.jaksky.dozer.b.codebook.TransTypeCodebook
Actual types:
java.lang.String
我的TransTypeCodebook课程
public class TransTypeCodebook extends Codebook {
private int code;
private String label;
private TransTypeCodebook(int code, String label) {
this.code = code;
this.label = label;
}
public int getCode() {
return code;
}
public String getLabel() {
return label;
}
public static TransTypeCodebook getCodebook(int code) {
TransTypeCodebook result;
switch (code) {
case 0:
result = new TransTypeCodebook(0, "Case0");
break;
case 1:
result = new TransTypeCodebook(1, "Case1");
break;
default:
result = new TransTypeCodebook(code, "Not a valid code");
}
return result;
}
}
映射器部分
<field>
<a>transType</a>
<b create-method="getCodebook">transTypeCodebook</b>
</field>
转换型
transTypeCodebook
我设法通过自定义转换器解决了这个问题,但我不确定我是否理解自定义创建方法的概念,我想知道这个字符串是从哪里来的。有人能解释一下吗?我不太确定,但要使用这样的静态方法,需要指定它的完全限定名
<b create-method="your.domain.TransTypeCodebook.getCodebook">transTypeCodebook</b>
transTypeCodebook
这是在报告中说的