关于form表单提交出现400的错误解决
<label class="col-sm-3 control-label">开户日期:</label>
<div class="col-sm-9">
<input type="date" name="oppenaccountdate" class="form-control">
</div>
错误是date类型提交后类型格式不同由于是ssm项目 解决方法
使用WebDateBinder类进行转换
在Controller中添加 initBinder 注解方法
//处理表单的日期格式
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));//true:允许为空, false:不允许为空
}
被@InitBinder注解修饰的方法会在SpringMVC为参数设置值之前调用, 并对参数做一些处理. 在这个方法内我们注册了一个自定义的类型为"CustomDateEditor"的"属性编辑器", 对日期格式字符串做了转化的操作.
另外还有几种方法 通过另一个博主的博客解决的问题 [https://blog.csdn.net/wn084/article/details/80171687]
在此记录