在使用 org.apache.commons.beanutils.BeanUtils.copyProperties(dest, orig)方法复制对象属性时,
若bean中有Date类型的属性,且可能为null时,可能会抛出一个异常:
rg.apache.commons.beanutils.ConversionException: No value specified for 'Date'
解决方案如下:
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
ConvertUtils.register(new DateConverter(null), java.util.Date.class);//添加这一行代码,重新注册一个转换器,也可以自定义
BeanUtils.copyProperties(dest, orig);
本文介绍在使用BeanUtils.copyProperties方法时遇到的问题及解决方案,特别是针对Date类型属性可能出现的ConversionException异常。
629

被折叠的 条评论
为什么被折叠?



