public class Test {
public static void main(String[] args) {
BeanOne one = new BeanOne();//新对象
BeanTwo two = new BeanTwo();
two.setAge(11);
two.setTel("123");
BeanThree three = new BeanThree();
three.setName("张三");
method1(one,two);
method1(one,three);
}
private static void method1(Object o1,Object o2) {
BeanUtils.copyProperties(o2, o1, getNullPropertyNames(o2));
System.out.println(o1.toString());
}
/**
* @Description <p>获取到对象中属性为null的属性名 </P>
* @param source 要拷贝的对象
* @return
*/
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd
关于从参数中获取想要的属性,封装为新对象并CRUD的操作
最新推荐文章于 2023-03-03 21:40:15 发布