spring mvc 接受Date型別資料,使用轉換
阿新 • • 發佈:2019-02-11
在controller中新增這個方法 /** * TODO:初始化接收的日期型別不然Date接收不到String型別 * @param binder */ @InitBinder public void dateBinder(WebDataBinder binder) { //The date format to parse or output your dates SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //Create a new CustomDateEditor CustomDateEditor editor = new CustomDateEditor(dateFormat, true); //Register it as custom editor for the Date type binder.registerCustomEditor(Date.class, editor); }