用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));
}
即可。
解决SpringMVC表单400错误
本文介绍了一个关于SpringMVC中表单提交出现400错误的问题及解决方案。该错误由日期字段为空引起,通过调整日期编辑器的设置解决了问题。
975

被折叠的 条评论
为什么被折叠?



