BeanUtils.copyProperties的使用方法
作者:互联网
BeanUtils.copyProperties的使用方法
1.使用的是springframe包下的,BeanUtils.copyProperties(a,b)
把a属性拷贝给b属性
2.注意事项:
使用时
例如
a和b都用page封装起来
Page<Setmeal> a
Page<getSetmealPageRespDTO> b
getSetmealPageRespDTO中 等于 Setmeal+一个CategoryName属性
Page下面有{
private static final long serialVersionUID = 8545996863226528798L;
protected List<T> records;
protected long total;
protected long size;
protected long current;
}
BeanUtils.copyProperties(a,b)
把a属性拷贝给b属性
b的records是没有拷到的
BeanUtils.copyProperties(Setmeal,getSetmealPageRespDTO) 这种是可以
但是
BeanUtils.copyProperties(list<Setmeal>,list<getSetmealPageRespDTO>)这样是不行的
最后得出结论 在copy对象的时候 必须一致,即拷贝的属性必须 类型和字段名一致才能拷贝成功。
最后得出结论 在copy对象的时候 必须一致,即拷贝的属性必须 类型和字段名一致才能拷贝成功。
标签:BeanUtils,long,copyProperties,protected,拷贝,方法,属性 来源: https://www.cnblogs.com/superFw/p/16250322.html