天天看點

BeanUtils.copyProperties() 用法--部分轉

把一個類對象copy到另一個類對象(這兩個可以不同)。

1、org.apache.commons.beanutils.BeanUtils.copyProperties(dest, src) 

org.springframework.beans.BeanUtils.copyProperties(src, dest) 

注意:2者的入參順序不同,嚴重

 BeanUtils.copyProperties(source,target);

1、

spring的BeanUtils.copyProperties 要求property類型嚴格一緻,否則就出錯 

比如srcBean有一個屬性是Short, destBean有一個同名屬性,但是類型是Integer,就會出錯。

報這個錯誤:

2、

4、org.apache.commons.beanutils.BeanUtils.copyProperties 會把null的Integer轉換成0,再複制