AllExceptionHandler.java 646 B

123456789101112131415161718
  1. package com.mszlu.blog.handler;
  2. import com.mszlu.blog.vo.Result;
  3. import org.springframework.web.bind.annotation.ControllerAdvice;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. //对加了@Controller注解的方法进行拦截处理 AOP实现
  7. @ControllerAdvice
  8. public class AllExceptionHandler {
  9. //进行异常处理,处理Exception。class的异常
  10. @ExceptionHandler(Exception.class)
  11. @ResponseBody //返回json数据
  12. public Result doException(Exception ex){
  13. ex.printStackTrace();
  14. return Result.fail(-999,"system error");
  15. }
  16. }