类 GlobalExceptionHandler
java.lang.Object
cn.jrack.springboot.web.core.handler.GlobalExceptionHandler
全局异常处理器,将 Exception 翻译成 CommonResult + 对应的异常编号
- 作者:
- ZhaoYang
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Result<?>allExceptionHandler(javax.servlet.http.HttpServletRequest request, Throwable ex) Result<?>bindExceptionHandler(org.springframework.validation.BindException ex) 处理 SpringMVC 参数绑定不正确,本质上也是通过 Validator 校验Result<?>constraintViolationExceptionHandler(javax.validation.ConstraintViolationException ex) 处理 Validator 校验不通过产生的异常Result<?>defaultExceptionHandler(javax.servlet.http.HttpServletRequest req, Throwable ex) 处理系统异常,兜底处理所有的一切Result<?>httpRequestMethodNotSupportedExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException ex) 处理 SpringMVC 请求方法不正确Result<?>methodArgumentNotValidExceptionExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException ex) 处理 SpringMVC 参数校验不正确Result<?>methodArgumentTypeMismatchExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) 处理 SpringMVC 请求参数类型错误Result<?>missingServletRequestParameterExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException ex) 处理 SpringMVC 请求参数缺失Result<?>noHandlerFoundExceptionHandler(org.springframework.web.servlet.NoHandlerFoundException ex) 处理 SpringMVC 请求地址不存在Result<?>notLoginExceptionHandler(cn.dev33.satoken.exception.NotLoginException ex) 处理系统异常,兜底处理所有的一切Result<?>saTokenExceptionHandler(cn.dev33.satoken.exception.SaTokenException ex) 处理 SaToken 权限不足的异常Result<?>处理业务异常 ServiceException
-
构造器详细资料
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
方法详细资料
-
allExceptionHandler
-
missingServletRequestParameterExceptionHandler
@ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public Result<?> missingServletRequestParameterExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException ex) 处理 SpringMVC 请求参数缺失例如说,接口上设置了 @RequestParam("xx") 参数,结果并未传递 xx 参数
-
methodArgumentTypeMismatchExceptionHandler
@ExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) public Result<?> methodArgumentTypeMismatchExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) 处理 SpringMVC 请求参数类型错误例如说,接口上设置了 @RequestParam("xx") 参数为 Integer,结果传递 xx 参数类型为 String
-
methodArgumentNotValidExceptionExceptionHandler
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public Result<?> methodArgumentNotValidExceptionExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException ex) 处理 SpringMVC 参数校验不正确 -
bindExceptionHandler
@ExceptionHandler(org.springframework.validation.BindException.class) public Result<?> bindExceptionHandler(org.springframework.validation.BindException ex) 处理 SpringMVC 参数绑定不正确,本质上也是通过 Validator 校验 -
constraintViolationExceptionHandler
@ExceptionHandler(javax.validation.ConstraintViolationException.class) public Result<?> constraintViolationExceptionHandler(javax.validation.ConstraintViolationException ex) 处理 Validator 校验不通过产生的异常 -
noHandlerFoundExceptionHandler
@ExceptionHandler(org.springframework.web.servlet.NoHandlerFoundException.class) public Result<?> noHandlerFoundExceptionHandler(org.springframework.web.servlet.NoHandlerFoundException ex) 处理 SpringMVC 请求地址不存在注意,它需要设置如下两个配置项: 1. spring.mvc.throw-exception-if-no-handler-found 为 true 2. spring.mvc.static-path-pattern 为 /statics/**
-
httpRequestMethodNotSupportedExceptionHandler
@ExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException.class) public Result<?> httpRequestMethodNotSupportedExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException ex) 处理 SpringMVC 请求方法不正确例如说,A 接口的方法为 GET 方式,结果请求方法为 POST 方式,导致不匹配
-
saTokenExceptionHandler
@ExceptionHandler(cn.dev33.satoken.exception.SaTokenException.class) public Result<?> saTokenExceptionHandler(cn.dev33.satoken.exception.SaTokenException ex) 处理 SaToken 权限不足的异常来源是,使用 @SaTokenException 进行权限及登录拦截
-
serviceExceptionHandler
@ExceptionHandler(cn.jrack.core.exception.ServiceException.class) public Result<?> serviceExceptionHandler(ServiceException ex) 处理业务异常 ServiceException例如说,商品库存不足,用户手机号已存在。
-
defaultExceptionHandler
@ExceptionHandler(java.lang.Exception.class) public Result<?> defaultExceptionHandler(javax.servlet.http.HttpServletRequest req, Throwable ex) 处理系统异常,兜底处理所有的一切 -
notLoginExceptionHandler
@ExceptionHandler(cn.dev33.satoken.exception.NotLoginException.class) public Result<?> notLoginExceptionHandler(cn.dev33.satoken.exception.NotLoginException ex) 处理系统异常,兜底处理所有的一切
-