使用BeanUtils.copyProperties复制对象属性时报错:
org.apache.commons.beanutils.ConversionException: No value specified for 'Date'
at org.apache.commons.beanutils.converters.AbstractConverter.handleMissing(AbstractConverter.java:310)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:136)
at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:60)
at org.apache.commons.beanutils.BeanUtilsBean.convert(BeanUtilsBean.java:1074)
at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:437)
at org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:286)
at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:137)
对象属性有Date类型为null时,使用org.apache.commons.beanutils复制对象转换异常。
解决方法1:
复制前加代码: ConvertUtils.register(new DateConverter(null), java.util.Date.class);
解决方法2:
使用spring的BeanUtils.copyProperties:
org.springframework.beans.BeanUtils.copyProperties