How SpringMvc exception handling and common comment

1.SpringMvc exception handling:

Topical treatment with 1.1 annotations @ExceptionHandler

@ExceptionHandler   // When this method will be processed by the abnormality occurs in the class, Exception process receives the exception object 
    public ModelAndView error (Exception Exception) { 
        ModelAndView Music Videos = new new ModelAndView (); 
        mv.addObject ( "error" , exception.getMessage ()); 
        mv.setViewName ( "error" );
         return Music Videos; 
    }

1.2 define a global exception class. @ControllerAdvice: mark to receive global unusual class

@ControllerAdvice
 public  class ExceptionController { 
    @ExceptionHandler   // when an abnormality occurs can be processed by this method, Exception process receives the exception object 
    public ModelAndView error (Exception Exception) { 
        ModelAndView Music Videos = new new ModelAndView (); 
        mv.addObject ( " error " , exception.getMessage ()); 
        mv.setViewName ( " error " );
         return Music Videos; 
    } 
}

2.Springmvc: Common Annotations

  @Controller: annotation class is class control layer.

  @RequestMapping: mark the requested address

  @ResponseBody: The java object into json object.

  @Valid: labeling the parity data

  @PathVariable: accepts uri parameter value assigned address method

  @SessionAttributes : The requset values assigned to the session in

  @RequestParam : reception parameters

  @ExceptionAdvice: labeling a class Exception class

  @ExceptionHandler: labeling method is a method for exception handling.

  @InitBinder: processing date and time parameters

  @ControllerAdvice: signs of abnormal reception class global

Learn more about the Reference Site: https://www.cnblogs.com/leskang/p/5445698.html

Guess you like

Origin www.cnblogs.com/mcl2238973568/p/11470185.html