String类型日期自动转Date数据类型


表单提交时候"Failed to convert property value of type [java.lang.String] to...

需要在核心控制器Controller加这个

@InitBinder

protected void initBinder(WebDataBinder binder) {
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

就能实现String类型的日期格式向Date类型的转换了!!!

 

前端部分的代码如下:

<tr>
  <td>结账时间</td>
  <td>
    <input type="text" name="payTime"
          value='  <fmt:formatDate value="${ orderInfo.payTime }"
          pattern="yyyy-MM-dd HH:mm:ss" />  '>
  </td>
</tr>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM