简体   繁体   English

具有集合和set-method属性的推土​​机Bean映射器配置

[英]Dozer Bean Mapper Configuration with Collections and set-method attribute

i habe a question concerning Dozer Bean Mapping. 我有一个关于推土机豆映射的问题。 I have the follwing xml configuration parts (i don´t understand some of this facts): 我有以下xml配置部分(我不了解其中的某些事实):

<mapping>
    <class-a>
        entity.template.TemplateEntity
    </class-a>
    <class-b>dto.template.TemplateDto
    </class-b>
    <field>
        <a set-method="setLang" get-method="getLang">lang</a>
        <b set-method="setLang" get-method="getLang">lang</b>
        <a-hint>entity.template.TemplateLanguageEntity</a-hint>
        <b-hint>dto.template.TemplateLanguageDto</b-hint>
    </field>
</mapping>

What is the concret meaning of "set-method="setLang" get-method="getLang""? “ set-method =” setLang“ get-method =” getLang“”的具体含义是什么?

What does the Dozer Bean Mapper do in this part? 推土机Bean映射器在这部分做什么? There is no other configuration, which describes, how to two collection should be mapped? 没有其他配置,这说明,两个集合应该如何映射?

<a-hint>entity.template.TemplateLanguageEntity</a-hint>
<b-hint>dto.template.TemplateLanguageDto</b-hint>

Does the Dozer Mapper map all fields automatically, which are founded by them if no configuration was set? 如果未设置任何配置,推土机映射器是否会自动映射所有由它们创建的字段?

Thanks for helping ! 感谢您的帮助!

Greetz Marwief 格蕾兹·马维夫(Greetz Marwief)

  • What is the concret meaning of "set-method="setLang" get-method="getLang""? “ set-method =” setLang“ get-method =” getLang“”的具体含义是什么?

Beans that might have unorthodox getter and setter methods, Dozer support user specified setter and getter methods.To make a bi-directional mapping in this case, look at the following example below. 可能具有非常规getter和setter方法的Bean,Dozer支持用户指定的setter和getter方法。在这种情况下,要进行双向映射,请看下面的示例。

The source field in element A specifies a custom setter method and getter method using attributes. 元素A中的source字段使用属性指定了自定义setter方法和getter方法。

<field>
  <a set-method="placeValue" get-method="buildValue">value</a>
  <b>value</b> 
</field>
  • What does the Dozer Bean Mapper do in this part? 推土机Bean映射器在这部分做什么? There is no other configuration, which describes, how to two collection should be mapped? 没有其他配置,这说明,两个集合应该如何映射?

Understand the Custom set() and get() methods dozer documentation . 了解自定义set()和get()方法推土机文档

Lets take for example if we are mapping a String to an ArrayList by calling the addIntegerToList() method. 让我们举个例子,如果我们通过调用addIntegerToList()方法将String映射到ArrayList。 Note that this is defined as a one-way field type since we can not map an ArrayList to a String. 请注意,由于我们无法将ArrayList映射到String,因此将其定义为单向字段类型。

<!-- we can not map a ArrayList to a String, 
         hence the one-way mapping -->
    <field type="one-way">         
      <a>integerStr</a>
      <b set-method="addIntegerToList">integerList</b>
    </field>
  • Does the Dozer Mapper map all fields automatically, which are founded by them if no configuration was set? 如果未设置任何配置,推土机映射器是否会自动映射所有由它们创建的字段?

Yes, Dozer Mapper maps all the fields automatically from class-A to class-B iff both the field names are same. 是的, iff both the field names are same. ,Dozer Mapper会自动将所有字段从A类映射到B类iff both the field names are same.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM