I am a Solivagant
Lofter    Posts     新文章     文章管理     新日记     日记管理

[Spring MVC] 表单提交日期转换问题,比如可能导致封装实体类时400错误

  三种格式的InitBinder

@InitBinder//https://stackoverflow.com/questions/20616319/the-request-sent-by-the-client-was-syntactically-incorrect-spring-mvc-jdbc-te
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
@InitBinder// 弟弟通过qq发送的
public void initBinder(ServletRequestDataBinder binder){
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),
true));
}
@InitBinder//露露通过飞秋发送的
public void initBinder(ServletRequestDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(
new SimpleDateFormat("yyyy-MM-dd"), true));
}

posted @ 2018-07-05 22:15  宛如ZZ  阅读(463)  评论(0编辑  收藏  举报