对象属性拷贝

使用org.springframework.beans.BeanUtils的对象拷贝

1、代码

1
2
3
4
5
6
7
8
public static void main(String[] args) {
Student stu=new Student();
CollegeStudent col=new CollegeStudent("段友元",22,"男");
System.err.println(col);
System.err.println(stu);
BeanUtils.copyProperties(col,stu);
System.err.println(stu);
}

2、运行结果

1
2
3
CollegeStudent{name='段友元', age=22, gender='男'}
Student{name='null', age=null}
Student{name='段友元', age=22}