实现自定义类型转换器

一、编写自定义转换类
public class StringToDateConverter implements Converter<String,Date> {

/**
*
* @param //传入进来字符串
* @return
*/
@Override
public Date convert(String str) {
if(str == null){
throw new RuntimeException("请您传入数据");
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
// 把字符串转换日期
return df.parse(str);
} catch (Exception e) {
throw new RuntimeException("数据类型转换出现错误");
}
}
}

二、在springmvc.xml进行配置








posted @ 2020-07-12 20:48  jock_javaEE  阅读(323)  评论(0)    收藏  举报