springMVC的自定义类型转换

在页面与前端控制器之间,出现的类型转换问题,如果想要自己实现一个类型转换:

  1. public class StringDateConvert implements Converter<String, Date> { @Override public Date convert(String source) { //1.判断是否为空 if (source == null) { throw new RuntimeException("请输入正常日期"); } System.out.println("首先,写实现converter类的类,其次,将其加入springMvVC中,最后,通过MvC启动该类的使用"); //2.自定义 DateFormat df = new SimpleDateFormat("yyyy-MM-DD"); try { return df.parse(source); } catch (ParseException e) { throw new RuntimeException("w,跳转错误"); } } }[2.配置注册springMVC的自定义类型转换springMVC的自定义类型转换]3.加入容器并启用
    springMVC的自定义类型转换