org.apache.commons.beanutils.BeanUtils 拷贝属性为对象的属性,拷贝地址

org.apache.commons.beanutils.BeanUtils 拷贝属性为对象的属性,拷贝地址_第1张图片import org.apache.commons.beanutils.BeanUtils;


import com.sl.sys.entity.Department;
import com.sl.sys.entity.Employee;


public class TestBeanUtils {

public static void main(String[] args) throws Exception {

Department dept = new Department();
dept.setId(1);
dept.setName("IT");

Employee emp = new Employee();
emp.setId(1);
emp.setDept(dept);
emp.setName("Mr Wang");

Employee emp2 = new Employee();
BeanUtils.copyProperties(emp2, emp);

dept.setName("Sale");

System.out.println(emp2);//此时emp2的dept名称字段name为Sale

}

}

由此可看拷贝的是属性若是为对象,则拷贝的为地址

你可能感兴趣的:(个人总结,解决方案,自导自演,技术学习)