https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc---update--比如你在代码中抛出了一个UserNotExistException异常,下面的代码就可以直接捕获 @ControllerAdvice @ResponseBody public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(UserNotExistException.class) public WrapResponse handleUserNotExist(){ return new WrapResponse().failure("用户名不存在"); } }
https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
---update--
比如你在代码中抛出了一个UserNotExistException异常,下面的代码就可以直接捕获