使用Spring提供的BeanUtils.copyProperties()方法報錯:Could not copy property 'xxx' from source to target



使用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的屬性類型使用包裝類型,不要使用基本類型。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM