admin管理员组文章数量:1635968
前言:
最近小编正在做一个功能,需要将一个实体复制给重新定义的相同实体的时候,使用BeanUtils.copyProperties(source, target)时,一直抛异常,控制台也没有打印出来,很是苦恼,不知道是哪里出问题了,于是百度了一下说属性里面存在空值,然后就尝试了所以使用各种办法始终没有解决。于是采用try..catch ,抓住了这个异常。今天分享给大家。
内容:
一、Java复制有好几种方法:
1、BeanUtils.copyProperties(source, target)
source 为源,target为目标,将源的值复制给目标。下面同理。
2、PropertyUtils.copyProperties(target,source);
二、问题:“java.lang.IllegalArgumentException: No destination bean specifie”
这句话的意思是:目标bean 不规范。
也就是说我定义的目标target( redsaleSettleVo)不规范。
(1)我原来的:
saleSettleVo redsaleSettleVo =null;
saleSettleVo saleSettleVo1 = saleSettleService.getSaleSettleById(vo.getId());
BeanUtils.copyProperties(saleSettleVo1,redsaleSettleVo);
(2)现在的:
saleSettleVo redsaleSettleVo =new saleSettleVo();
saleSettleVo saleSettleVo1 = saleSettleService.getSaleSettleById(vo.getId());
//将saleSettleVo1的值复制给redsaleSettleVo
BeanUtils.copyProperties(saleSettleVo1,redsaleSettleVo);
(3)之所以一直都抛异常,是因为没有重新实例化saleSettleVo。
本文标签: 抛出异常JavacopyPropertiesBeanUtils
版权声明:本文标题:使用BeanUtils.copyProperties()时,抛出异常“java.lang.IllegalArgumentException: No destination bean specifie” 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729216123a1190453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论