BeanUtils API中使用ConvertUtils向BeanUtils注册一个日期转换器

 1 ConvertUtils.register(new Converter(){
 2       public Object convert(Class type, Object value){
 3          if(value == null){
 4             return null;
 5          }
 6          if(!(value instanceof String)){
 7             throws ConversionException("只支持八种基本默认数据类型转换");
 8          }
 9          String str = (String)value;
10          if(str.trim().equals("")){
11             return null;
12          }
13          SimpleDateFormat dr = new SimpleDateFormat("yyyy-MM-dd");
14          try{
15          return dr.parse(str);
16          }catch(ParseException e){
17            throws RuntimeException(e);  //e,异常链不可断
18          }
19       }
20 }, Date.class)
原文地址:https://www.cnblogs.com/lyunyu/p/3434546.html