JavaBean之間拷貝利器-Dozer 如果現在還是原始的手動拷貝或者使用BeanUtil 趕緊換吧
典型的解決方案就是手動拷貝,弊端很明顯,代碼中充斥大量Set Get方法,真正的業務沒埋藏與值的拷貝之中。另一種方案就是使用BeanUtil,但BeanUtil不夠很好的靈活性,又時候還不得不手動拷貝。
對于這種重復沒有實際意義的拷貝難道沒有終結解決方案嗎?! Dozer 一把JavaBean利器。(http://dozer.sourceforge.net/)
什么是Dozer?
看看官方的定義:
another. Typically, these Java Beans will be of different complex types.
Dozer supports simple property mapping, complextype mapping, bi-directional mapping, implicitexplicit mapping, as well as recursive
mapping.This includes mapping collection attributes that also need mapping at the element level.
如何使用呢? 類似BeanUtil 很簡單,如果兩個javaBean之間,屬性名相同,類型為基本類型,那么下面代碼就OK了,基本沒有學習曲線。
DestinationObject destObject = mapper.map(sourceObject, DestinationObject.class);
or
DestinationObject destObject = new DestinationObject();
mapper.map(sourceObject, destObject);
posted on 2009-04-12 22:11 advincenting 閱讀(3169) 評論(10) 編輯 收藏