org.apache.commons.beanutils.BeanUtils 拷贝属性为对象的属性,拷贝地址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

}

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

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

相关文章: