【问题标题】:Mapping properties of beans in different packages using dozer使用推土机映射不同包中bean的属性
【发布时间】:2012-05-31 10:33:09
【问题描述】:

我正在尝试使用推土机映射位于不同包中的 bean 的属性,例如:

<mapping> 
 <class-a>com.naeem.schema.basictypes.Birth</class-a> 
 <class-b>com.naeem.schema.forms.n840.DateStore</class-b> 
  <field>
   <a>countryOfBirth</a>
   <b>countryOfBirth</b> 
 </field> 
</mapping>

这在推土机中是否可行。谢谢

【问题讨论】:

    标签: properties javabeans packages dozer


    【解决方案1】:

    是的,它可以在推土机中使用。 默认情况下,dozer 会将源对象中的所有属性映射到目标对象中的同名属性。所以在你的情况下,这两个类都有一个同名的属性 countryOfBirth 。所以你甚至不必编写映射文件。以下就足够了:

    DozerMapper mapper = new DozerMapper();
    Birth birth = new Birth();
    //set different fields of birth object
    DateStore dateStore =  new DateStore();
    mapper.map(birth,dateStore);
    

    或者,或者,

    DozerMapper mapper = new DozerMapper();
    Birth birth = new Birth();
    //set different fields of birth object
    DateStore dateStore =  mapper.map(birth,DateStore.class);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      相关资源
      最近更新 更多