springboot全局异常管理
当你的controller中出现(也不限于controller)异常时,就可以配置一个异常页面展示给用户。
你需要使用一个异常类。在发生异常时会跳进这个类你需要使用@RestControllerAdvice这个注解
当普通的数据时(不是json)数据
建立一个异常页面
```
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>捕获全局异常</title>
</head>
<body>
<h1>出错</h1>
<div th:text="${url}"></div>
<div th:text="${exception.message}"></div>
</body>
</html>```
和一个捕获异常的类
@RestControllerAdvice
public class ErrorExceptionHandler {
public final static String CK_ERROR_VIEW = "error";
@ExceptionHandler(value = Exception.class)
public Object errorHandler(HttpServletRequest htt