簡體   English   中英

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

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

我有一個關於推土機豆映射的問題。 我有以下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>

“ set-method =” setLang“ get-method =” getLang“”的具體含義是什么?

推土機Bean映射器在這部分做什么? 沒有其他配置,這說明,兩個集合應該如何映射?

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

如果未設置任何配置,推土機映射器是否會自動映射所有由它們創建的字段?

感謝您的幫助!

格蕾茲·馬維夫(Greetz Marwief)

  • “ set-method =” setLang“ get-method =” getLang“”的具體含義是什么?

可能具有非常規getter和setter方法的Bean,Dozer支持用戶指定的setter和getter方法。在這種情況下,要進行雙向映射,請看下面的示例。

元素A中的source字段使用屬性指定了自定義setter方法和getter方法。

<field>
  <a set-method="placeValue" get-method="buildValue">value</a>
  <b>value</b> 
</field>
  • 推土機Bean映射器在這部分做什么? 沒有其他配置,這說明,兩個集合應該如何映射?

了解自定義set()和get()方法推土機文檔

讓我們舉個例子,如果我們通過調用addIntegerToList()方法將String映射到ArrayList。 請注意,由於我們無法將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>
  • 如果未設置任何配置,推土機映射器是否會自動映射所有由它們創建的字段?

是的, 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