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