位置:首页 > > 使用InitBinder来处理Date类型的参数

使用InitBinder来处理Date类型的参数

 //the parameter was converted in initBinder
 @RequestMapping("/date")
 public String date(Date date){
     System.out.println(date);
     return "hello";
 }
    
 //At the time of initialization,convert the type "String" to type "date"
 @InitBinder
 public void initBinder(ServletRequestDataBinder binder){
     binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
             true));
 }