package com.guozz.test;
public class TestA {
private String a;
private String b;
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
package com.guozz.test;
public class TestB {
private String a;
private String b;
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
package com.guozz.test;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
public class Test {
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
TestA testA = new TestA();
testA.setA("aa");
testA.setB("bb");
TestB testB = new TestB();
BeanUtils.copyProperties(testB, testA);
System.out.println(testB.getA());
System.out.println(testB.getB());
}
}
输出
aa
bb