@ControllerAdvice public class ExceptionConfig extends Object
| 构造器和说明 |
|---|
ExceptionConfig() |
| 限定符和类型 | 方法和说明 |
|---|---|
Ret<Void> |
handler(javax.validation.ConstraintViolationException e)
请求参数校验失败异常处理
即 @Valid 校验失败
|
Ret<Void> |
handler(Exception e)
默认异常处理
|
Ret<Void> |
handler(org.springframework.http.converter.HttpMessageNotReadableException e)
请求体不可读错误异常处理
如 要求接收一个 json 请求体, 但是未读取到
|
Ret<Void> |
handler(org.springframework.web.HttpRequestMethodNotSupportedException e)
请求方法错误异常处理
即 POST 接口, 请求时用了 GET 方法
|
Ret<Void> |
handler(org.springframework.web.bind.MethodArgumentNotValidException e)
请求参数校验失败异常处理
即 @Validated 校验失败
|
Ret<Void> |
handler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException e)
请求参数类型不匹配异常处理
如要 Integer 参数, 却传了字符串, 且无法转换为 Integer eg: Failed to convert value of type 'java.lang.String' to
required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "hello"
|
Ret<Void> |
handler(org.springframework.web.bind.MissingServletRequestParameterException e)
请求参数缺失异常处理
如要 name 字段, 却传递 eg: Required String parameter 'name' is not present
|
Ret<Void> |
handler(ServiceException e)
业务异常处理
如支付失败
|
@ExceptionHandler(value=ServiceException.class) @ResponseBody public Ret<Void> handler(ServiceException e)
e - 异常对象@ExceptionHandler(value=org.springframework.web.bind.MissingServletRequestParameterException.class) @ResponseBody public Ret<Void> handler(org.springframework.web.bind.MissingServletRequestParameterException e)
e - 异常对象@ExceptionHandler(value=org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) @ResponseBody public Ret<Void> handler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException e)
e - 异常对象@ExceptionHandler(value=org.springframework.web.bind.MethodArgumentNotValidException.class) @ResponseBody public Ret<Void> handler(org.springframework.web.bind.MethodArgumentNotValidException e)
e - 异常对象@ExceptionHandler(value=javax.validation.ConstraintViolationException.class) @ResponseBody public Ret<Void> handler(javax.validation.ConstraintViolationException e)
e - 异常对象@ExceptionHandler(value=org.springframework.web.HttpRequestMethodNotSupportedException.class) @ResponseBody public Ret<Void> handler(org.springframework.web.HttpRequestMethodNotSupportedException e)
e - 异常对象@ExceptionHandler(value=org.springframework.http.converter.HttpMessageNotReadableException.class) @ResponseBody public Ret<Void> handler(org.springframework.http.converter.HttpMessageNotReadableException e)
e - 异常对象@ExceptionHandler(value=java.lang.Exception.class) @ResponseBody public Ret<Void> handler(Exception e)
e - 异常对象Copyright © 2021. All rights reserved.