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

 ConvertUtils.register(new Converter(){
public Object convert(Class type, Object value){
if(value == null){
return null;
}
if(!(value instanceof String)){
throws ConversionException("只支持八种基本默认数据类型转换");
}
String str = (String)value;
if(str.trim().equals("")){
return null;
}
SimpleDateFormat dr = new SimpleDateFormat("yyyy-MM-dd");
try{
return dr.parse(str);
}catch(ParseException e){
throws RuntimeException(e); //e,异常链不可断
}
}
}, Date.class)
上一篇:ExtJS MVC学习手记 2


下一篇:WCF入门(22)