Java不同对象之间复制属性

// 导入包
import org.springframework.beans.BeanUtils;

/**
* 调用工具复制2个对象之间的属性 2个JavaBean对象复制的属性名相同 浅拷贝
* @param target
* @return
*/
private Class2 copyProperties(Class2 target){
// 不需要复制的字段
String[] ignoreProperties = new String[]{"bz","createdat","createdby","updatedat","updatedby"};
Class1 source= myService.get(target.getId());
BeanUtils.copyProperties(source,target,ignoreProperties);
return target;
}
原文地址:https://www.cnblogs.com/liw66/p/10484244.html