使用spring框架,在修改页面(修改一个日期,页面日期格式为 yyyy-MM-dd HH:mm:ss)时出现错误:
<td>
<input type="text" name="createtime"
value="<fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>" />
</td>

The request sent by the client was syntactically incorrect.客户端发送的请求语法是错误的
解决办法:在你的controller里加上如下代码
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
Spring框架日期编辑器配置

本文介绍了在使用Spring框架时如何正确配置日期编辑器来处理特定格式的日期输入,特别是针对yyyy-MM-dd HH:mm:ss格式的日期字段。通过在Controller中添加定制的日期编辑器,可以确保前端传来的日期字符串能够被正确解析。
4731

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



