1. 程式人生 > >SpringMVC頁面傳參到後臺,日期字串報錯處理

SpringMVC頁面傳參到後臺,日期字串報錯處理

在controller類中加入如下程式碼,
如果頁面的查詢格式都是同一格式的日期,則直接放到BaseController類中即可:

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