我想我想通了。今天发生在我身上。我只是对它进行了一些小测试,但它没有用。这是代码:
static class TesteP {
private String a;
private String b;
private String c;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return this.b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
return this.c;
}
public void setC(String c) {
this.c = c;
}
@Override
public String toString() {
return new ToStringBuilder(this.getClass()).add("a", this.a).add("b", this.b).toString();
}
}
static class RestP {
private String a;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
@Override
public String toString() {
return this.a;
}
}
public static void main(String[] args)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
TesteP p = new TesteP();
p.setA("AAAA");
p.setB("BBB");
TesteP pp = new TesteP();
RestP p2 = new RestP();
p2.setA("aaaa");
PropertyUtils.copyProperties(p,p2);
}
它解决了这个问题,使课程公开。也许你的一门课不是公开的。这是我的解决方案:
public static class TesteP {
private String a;
private String b;
private String c;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return this.b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
return this.c;
}
public void setC(String c) {
this.c = c;
}
@Override
public String toString() {
return new ToStringBuilder(this.getClass()).add("a", this.a).add("b", this.b).toString();
}
}
public static class RestP {
private String a;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
@Override
public String toString() {
return this.a;
}
}
public static void main(String[] args)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
TesteP p = new TesteP();
p.setA("AAAA");
p.setB("BBB");
TesteP pp = new TesteP();
RestP p2 = new RestP();
p2.setA("aaaa");
PropertyUtils.copyProperties(p,p2);
}