ExceptionAdvice.java 688 B

12345678910111213141516171819202122232425
  1. package com.zy.bms.config;
  2. import com.zy.bms.common.ServerResponse;
  3. import org.springframework.web.bind.annotation.ExceptionHandler;
  4. import org.springframework.web.bind.annotation.RestControllerAdvice;
  5. import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
  6. /**
  7. * 全局异常拦截
  8. *
  9. * @author chenyi
  10. * Create on 2019/10/21
  11. */
  12. @RestControllerAdvice
  13. public class ExceptionAdvice {
  14. /**
  15. * 对参数类型不匹配异常做统一拦截处理
  16. */
  17. @ExceptionHandler(value = MethodArgumentTypeMismatchException.class)
  18. public ServerResponse MethodArgumentTypeMismatchExceptionHandler() {
  19. return ServerResponse.error();
  20. }
  21. }