springmvc 表单内含有时间类型字段,提交时404问题.

jsp表单中的时间字段

  <div>				
      有效日期:
        <input type="text" name="validity" class="form-control" onFocus="WdatePicker({lang:'zh-cn'})" 
	value="<fmt:formatDate value='${user.validity}' pattern='yyyy-MM-dd'/>">				
  </div>

对应的controller类中添加如下代码 (jsp表单定义的时间格式,和controller类中的时间格式必须保持一致)

// 解决表单提交时实体对象中date类型的转换
@InitBinder
public void initBinder(WebDataBinder binder) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(true);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

`

posted on 2020-12-09 09:06  黎明前的守护  阅读(176)  评论(0)    收藏  举报