java之对象拷贝(A对象中的数据拷贝到B对象)

使用BeanUtils.copyProperties(source,target);方法

(BeanUtils.copyProperties()方法是浅拷贝)

 


//我要把
PrjPlanDetailEntity 对象的数据拷贝到 PrjBdgDetailEntity,只要他们有相同的字段,数据就会拷贝过去

PrjPlanDetailEntity p1 = new PrjPlanDetailEntity();
p1.setPlanStartDate(new Date());
p1.setPlanEndDate(DateUtils.parse("2020-12-16", "yyyy-MM-dd"));

PrjBdgDetailEntity p2 = new PrjBdgDetailEntity();
BeanUtils.copyProperties(p2, p1);
System.out.println(p2.getPlanEndDate());


p2对象的planEndDate字段打印出来数据说明拷贝成功了

 

 

posted @ 2020-12-17 09:00  下课后我要去放牛  阅读(1422)  评论(0编辑  收藏  举报