使用Spring提供的BeanUtils.copyProperties()方法報錯:Could not copy property 'xxx' from source to target; nested exception is java.lang.IllegalArgumentException
調用的方法:org.springframework.beans.BeanUtils.copyProperties(Object source, Object target)
報錯:
org.springframework.beans.FatalBeanException: Could not copy property 'adgroupId' from source to target; nested exception is java.lang.IllegalArgumentException
at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:615)
at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:528)
...
分析:
在使用Spring提供的BeanUtils.copyProperties(Object source, Object target)方法時,如果target中的屬性含有基本類型,而source中對應的屬性值為null,
則copy時,就相當於給一個基本類型賦值null,故報錯。
解決方法:
javaBean的屬性類型使用包裝類型,不要使用基本類型。