//自己指定一个类型转换器(将String转成Date)
ConvertUtils.register(new Converter() {
@Override
public Object convert(Class clazz, Object value) {
//将string转成date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date parse = null;
try {
parse = format.parse(value.toString());
} catch (ParseException e) {
e.printStackTrace();
}
return parse;
}
}, Date.class);
BeanUtils内置的常用的转换器罗列一下吧。
- AbstractArrayConverter
- AbstractConverter
- ArrayConverter
- BigDecimalConverter
- BooleanArrayConverter
- BooleanConverter
- ByteArrayConverter
- ByteConverter
- CalendarConverter
- CharacterArrayConverter
- CharacterConverter
- ClassConverter
- ConverterFacade
- DateCOnverter
- DateTimeConverter
- DoubleConverter
- FloatArrayConverter
- FileConverter
- FloatConverter
- IntegerArrayConverter
- IntegerConverter
- LongConverter
- LondArrayCOnverter
- NumberConverter
- ShortArrayConverter
- ShortConverter
- SqlTimeConverter
- SqlTimestampConverter
- StringArrayConverter
- StringConverter
- URLConverter
GitHub : https://github.com/fxiaoyu97
微信公众号 : 三更编程菌
作者:卡洛小豆