1. //@ControllerAdvice将当前类标识为异常处理的组件
    2. @ControllerAdvice
    3. public class ExceptionController {
    4. //@ExceptionHandler用于设置所标识方法处理的异常
    5. @ExceptionHandler(ArithmeticException.class)
    6. //ex表示当前请求处理中出现的异常对象
    7. public String handleArithmeticException(Exception ex, Model model){
    8. model.addAttribute("ex", ex);
    9. return "error";
    10. }
    11. }