使用commons-beanutils-1.8.3.jar提供的BeanUtils类快速封装属性时,遇到的错误

来源:互联网 发布:can数据帧的格式结构 编辑:程序博客网 时间:2024/06/05 15:23

错误说明:dateconverter不支持默认字符串到“日期”转换。


解决办法:此时需要自定义转换器,将字符串转换成date类型。


 // 自定义类型转换器
// 参数1:类型转换器
// 参数2:要转换至的类型
ConvertUtils.register(new Converter() {


@Override
// 参数一:要转换成的类型
// 参数二:要转换的对象
public Object convert(Class arg0, Object arg1) {
// TODO Auto-generated method stub
// 将字符串转data
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(arg1.toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}, Date.class);

阅读全文
0 0
原创粉丝点击