spring-boot global exception capture
It can be used for unified return and internationalization of error information after SpringMVC request, and exception handling components can also be developed based on this type of extension
configure
@ControllerAdvice
public class CloudExceptionHandler {
@ExceptionHandler(value = Exception.class)
public void defaultExceptionHandler(HttpServletRequest request, Exception e){
//打印异常信息:
e.printStackTrace();
System.out.println("CloudExceptionHandler.defaultExceptionHandler()");
//TODO 可返回 json 需要加 @ResponseBody
//TODO 可返回 视图 ModelAndView
}
}