在Controller方法执行之前进行捕获请求,进行类型的转换

@ExceptionHandler(TypeMismatchException.class)
   public ModelAndView ParseException(Excetion ex,HttpServltRquser  request)
           ModelAndView   mv=new ModelAndView();
            mv.addObject("age",request.getparamter(s:"age"));
               mv.setViewName("/typeconverter.jsp");
                   return  mv;

}



     @InitBinder
            public void   initBinder(webDataBinder   binder){
                  binder.registerCustomEditor(Data.class,new              MyDateEditor());

}

@RequestMapping("/first")

//类型转化工作一定要是在真正的handler方法执行前执行.

public  String doFirst(DataBinder   binder){
         System。out.println(birtday+"=======");
             system.out.println(age+"========");
                      return  "/WELCOME.jsp"

}

  //重写setAstext

           public   void setAsText(String  source) throws    
IllegalArgumentException{
         SimpleDateFormat    sdf=getDateFormat(source);
                       try{
                             Date     date=sdf.parse(source);
                                      setValue(date);
                                            }catch (parseException    e){
                                                      e.printStackTrace();
                                                               }

                                                         }

  

原文地址:https://www.cnblogs.com/2652405350wch/p/7444726.html