2013-10-09 9 views
1

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

什麼是「設置方法=」 setLang「獲得法=‘getLang’」的形而下的意義?

Dozer Bean Mapper在這部分中做了什麼?沒有其他配置,它描述瞭如何映射兩個集合?

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

Dozer Mapper是否會自動映射所有字段,如果沒有設置配置,它們由它們創建?

感謝您的幫助!

格爾茨 Marwief

回答

1
  • 什麼是 「設置方法=」 setLang 「獲得法= 」getLang「」 的形而下的意義?可能具有非正統的getter和setter方法

豆類,推土機支持用戶指定的setter和getter methods.To進行雙向映射在這種情況下,看看下面的下面的例子。

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

<field> 
    <a set-method="placeValue" get-method="buildValue">value</a> 
    <b>value</b> 
</field> 
  • 什麼是推土機Bean的映射在這部分做什麼?沒有其他配置,它描述瞭如何映射兩個集合?

瞭解Custom set() and get() methods dozer documentation

舉例來說,如果我們通過調用addIntegerToList()方法將字符串映射到ArrayList。 請注意,由於我們無法將ArrayList映射到字符串,因此將其定義爲單向字段類型。

<!-- 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> 
  • 是否推土機映射自動映射所有領域,這是由他們創辦如果沒有配置設置?

是,推土機映射器映射的所有字段從類-A自動類-B iff both the field names are same.