有没有办法让 BeanUtils 使用 protected setXXX(X x)
方法?或者您知道执行此操作的其他方法吗?
类似于:
public class A{
private String text;
public String getText(){
return this.text;
}
protected void setText(String text){
this.text = text;
}
}
public class B{
private String text;
public String getText(){
return this.text;
}
protected void setText(String text){
this.text = text;
}
}
public static void main(String[] args){
A a = new A();
a.setText("A text");
B b = new B();
BeanUtils.copyProperties(b, a);
System.out.println(b.getText()); //A text
}
最佳答案
尝试使用 BULL (Bean Utils Light Library)
public static void main(String[] args) {
A a = new A();
a.setText("A text");
B b = BeanUtils.getTransformer(B.class).apply(a);
System.out.println(b.getText()); //A text
}
关于java - Beanutils.copyProperties 与 protected 设置方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29990286/