Java: Merge 2 “beans” to produce a new one

与世无争的帅哥 提交于 2019-12-23 03:24:10

问题


I need to take all the fields and collections from Bean1 and Bean2, sometimes apply some business logic, and produce Bean3 (all beans are hibernate/domain objects of the same type with a reasonably complex graph).

Any thoughts on how to do this? Done something similar in the past?

My ideas:

  1. Dozer (http://dozer.sourceforge.net/)
  2. BeanUtils (http://commons.apache.org/beanutils/)
  3. Handrolled solution
  4. A.N.Other cool solution?

Any recommendations?


回答1:


Dozer is a nice bean mapping tool. However, it won't perform any business logic, of course.

I should not be a problem to implement a business logic and to rely on Dozer for bean mapping. This is what I would do.




回答2:


Neither of the tools provides business logic - also it has to be implemented somehow. Bean utils are goot to access bean properties with standard notation. You may try groovy to implement business logic with nice syntax.



来源:https://stackoverflow.com/questions/12669977/java-merge-2-beans-to-produce-a-new-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!