BeanUtils与PropertyUtils

他们的copyProperties方法行为不太一样.

------------------------------------------------------------------------
值为null的属性类型       BeanUtils拷贝的值          PropertyUtils拷贝的值
------------------------------------------------------------------------
java.lang.Double         0.0                            null
java.lang.Integer          0                             null
java.lang.Long              0                             null
java.sql.Date                抛异常                        null
java.util.Date              null                          null
java.sql.Timestamp         抛异常                         null

看来还是PropertyUtils.copyProperties(Object dest, Object orig)原汁源味。

BeanUtils的妙处在于可以把String类型的'2011-01-02'转换为java.util.Date类型,所以这个方法在Struts1中收集浏览器表单数据转换为form bean时是非常重要的。

你可能感兴趣的:(PropertyUtils)