總結的兩個日期接收器
一 :前端傳字符串類型日期
條件:只會接收到 指定類型 日期yyyy-MM-dd可以按自己想的 寫
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
二:一股腦接收,不能確定到底接收的什麼類型日期數據
@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
// 處理Date類型
binder.registerCustomEditor(Date.class, new DateEditor());
binder.registerCustomEditor(String.class, new StringEditor());
}
如果前段是new Date()傳的日期,應該是不需要接收器