常用的bean复制属性的实现方式有:分别为Apache的BeanUtils和PropertyUtils,Spring的BeanUtils,Cglib的BeanCopier。
apche BeanUtils
BeanUtils.copyProperties(dest,orig);
PropertyUtils
PropertyUtils.copyProperties(dest,orig)
这两者的区别在与,PropertyUtils在拷贝对象时没有类型的转换,而BeanUtils已经包含了类型转换。
转换的支持常用的类型,但是java.util.Date类型除去。
扫描二维码关注公众号,回复:
676017 查看本文章
spring BeanUtils
org.springframework.beans.BeanUtils.copyProperties(frombean,
toBean)
cglib对象属性拷贝
BeanCopier bc = BeanCopier.create(FromBean.class, ToBean.class,
false);
bc.copy(orig,dest,null);
关于这几种对象属性的拷贝性能,请查考
http://www.cnblogs.com/kaka/archive/2013/03/06/2945514.html