BeanUtils.copyProperties的使用方法
阿新 • • 發佈:2022-05-09
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物件的時候 必須一致,即拷貝的屬性必須 型別和欄位名一致才能拷貝成功。