@InitBinder 前端传递date时间类型属性时,转换错误问题
在Controller里加上这段代码
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { public void setAsText(String value) { try { SimpleDateFormat dateFormat = new SimpleDateFormat('yyyy-MM-dd'); setValue(dateFormat.parse(value)); } catch(ParseException e) { setValue(null); } } public String getAsText() { return new SimpleDateFormat('yyyy-MM-dd').format((Date) getValue()); } }); }