BeanUtils.copyProperties 复制对象异常问题

    **BeanUtils.copyProperties 复制对象异常问题**

复制对象时 java.lang.IllegalArgumentException: No destination bean specified,

这个是目标的bean实体没有确定,异常代码如下:

CrmProcessOrdersParam crmProcessOrdersParam = null;
BeanUtils.copyProperties(crmProcessOrdersParam, crmProcessOrdersBean);

出现问题主要的原因是在复制对象过程中,如果有一方为null,则会抛出此异常!所以把目标实体实例化即可。

改正的代码:

CrmProcessOrdersParam crmProcessOrdersParam = new CrmProcessOrdersParam();
BeanUtils.copyProperties(crmProcessOrdersParam, crmProcessOrdersBean);

易错代码:
CrmProcessOrdersParam crmProcessOrdersParam = crmProcessOrdersParam Service.getById(id);
BeanUtils.copyProperties(crmProcessOrdersParam, crmProcessOrdersBean);

crmProcessOrdersParam Service.getById(id); 查询如果为空,就会出现如上问题。

你可能感兴趣的:(JAVA编程)