读书人

记录一个SpringMVC的400异常

发布时间: 2012-08-25 10:06:20 作者: rapoo

记录一个SpringMVC的400错误

用Spring MVC提交一个表单时报400错误:The request sent by the client was syntactically incorrect ().

原来是其中一个日期字段为空所致。代码如下:

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

?只用修改为:

@InitBinder    public void initBinder(WebDataBinder binder) {        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");        dateFormat.setLenient(false);        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));    }

?即可。

读书人网 >VC/MFC

热点推荐