我将变量值设置为 null,但遇到问题:
public class BestObject {
private Timestamp deliveryDate;
public void setDeliveryDate(Timestamp deliveryDate) {
this.deliveryDate = deliveryDate;
}
}
BeanUtils.setProperty(new BestObject(), "deliveryDate", null); // usually the values are not hardcoded, they come from configuration etc
这是错误:
org.apache.commons.beanutils.ConversionException: No value specified
at org.apache.commons.beanutils.converters.SqlTimestampConverter.convert(SqlTimestampConverter.java:148)
at org.apache.commons.beanutils.ConvertUtils.convert(ConvertUtils.java:379)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:999)
基本上它试图将 java.sql.Timestamp 值设置为 null,但由于某种原因它不起作用。
另一方面,我正在使用反射包装器 BeanUtils(http://commons.apache.org/proper/commons-beanutils/),也许这可以通过普通反射实现?