Could not copy property ‘commentCounts‘ from source to target; 解决方法

org.springframework.beans.FatalBeanException: Could not copy property 'commentCounts' from source to target; nested exception is java.lang.IllegalArgumentException
	at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:800)
	at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:701)
	at com.dxh.blog.service.impl.ArticleServiceImpl.copy(ArticleServiceImpl.java:75)
	at com.dxh.blog.service.impl.ArticleServiceImpl.copyList(ArticleServiceImpl.java:53)
	at com.dxh.blog.service.impl.ArticleServiceImpl.hotArticle(ArticleServiceImpl.java:133)
	at com.dxh.blog.dao.controller.ArticleController.hotArticle(ArticleController.java:34)
	

Could not copy property ‘commentCounts’ from source to target; nested exception is java.lang.IllegalArgumentException

Could not copy property ‘commentCounts‘ from source to target; 解决方法_第1张图片
Could not copy property ‘commentCounts‘ from source to target; 解决方法_第2张图片
原因:两个bean中 共同存在的属性的数据类型不匹配

可以想象到的是,如果源对象中某个属性值是空的话,那么value值也将为null,传给目标对象的对应属性的值也就是null。

所以,如果恰好该属性是基本类型的话,给一个基本类型赋值null,肯定会抛异常了!

参考方法 https://blog.csdn.net/rchm8519/article/details/7101911

你可能感兴趣的:(笔记,java,intellij-idea,spring,boot)