Spring MVC 处理时间字段

来源:互联网 发布:孙尚香铭文 知乎 编辑:程序博客网 时间:2024/05/02 01:53

用Bean 去接受前端表单提交的数据 如果Bean 中有Date 类型的字段

接收如字符串“2016-06-06” 就会报错

需要在Controller 类中加入如下方法

@InitBinderpublic void initBinder(WebDataBinder binder){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");    binder.registerCustomEditor(Date.class, new CustomDateEditor(df,false));   }


原创粉丝点击