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 拷贝属性为对象的属性,拷贝地址

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

相关文章:

  • 2019-12-26
  • 2021-09-13
  • 2021-11-30
  • 2021-09-18
  • 2021-10-18
  • 2021-12-05
  • 2021-12-06
  • 2021-08-01
猜你喜欢
  • 2021-09-18
  • 2019-11-07
  • 2021-09-12
  • 2021-09-18
  • 2021-08-14
  • 2021-09-28
  • 2020-04-23
相关资源
相似解决方案