我有以下域名结构:
abstract class Person { String name; //with getter and setter }
class Employer extends Person {}
class Employee extends Person {}
class Contract { Person contractor; //with getter and setter }
class PersonDTO implements Serializable { String name; String type; //type == 'Employee' or 'Employer' }
class ContractDTO implements Serializable { PersonDTO contractor; }
现在我设置了以下推土机映射:
<mapping>
<class-a>Person</class-a>
<class-b>PersonDTO</class-b>
</mapping>
<mapping>
<class-a>Employer</class-a>
<class-b>PersonDTO</class-b>
</mapping>
<mapping>
<class-a>Contract</class-a>
<class-b>ContractDTO</class-b>
</mapping>
我的问题涉及将字段Contract.contractor从B映射到A,因为字段Contract.contractor是一个抽象类,推土机无法猜测如何实现它。
所以我的问题很简单:如何向dozer表示,对于字段Contract.contractor的映射,它应该实例化Employer
if type == 'Employer
'和其他地方{{1}的实例}
感谢您的帮助。
答案 0 :(得分:0)
您可以使用提示进行此操作。 有点像这样:
<mapping>
<class-a>Contract</class-a>
<class-b>ContractDTO</class-b>
<field>
<a>contractor</a>
<b>contractor</b>
<a-hint>your.package.Employer, your.package.Employee</a-hint>
<b-hint>your.DTOpackage.EmployerDTO, your.DTOpackage.EmployeeDTO</b-hint>
</field>
</mapping>