开箱即用的 BeanUtils copyProperties 似乎无法处理从 boolean 对象属性到 boolean 基本属性的复制。
我想我可以创建并注册一个转换器来处理这个问题,但这似乎不起作用。
那么,如何使用 BeanUtils 将属性从类 Source 复制到类 Destination,其中:
public class Destination {
private boolean property;
public boolean isProperty() {
return property;
}
public void setProperty(boolean property) {
this.property = property;
}
}
public class Source{
private Boolean property;
public Boolean getProperty() {
return property;
}
public void setProperty(Boolean property) {
this.property = property;
}
}
最佳答案
try creating both
/*by default beanutils copyproperties looks for below method if you use either apache or spring flavour of beanutils.
always prefer using apache 1.9.2 ( fixed many bugs) but bit slow compared with spring beanutils.*/
public Boolean getProperty() {
return property;
}
//which is used by some frameworks
public Boolean isProperty() {
return property;
}
关于java - 如何使用 BeanUtils copyProperties 从 boolean 值复制到 boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/614734/