springboot定制错误处理页面
springboot错误页面处理
- 结构如下:
在template文件夹下新建error文件夹
在error新建4xx.html文件和5xx.html文件
2. 新建HelloController 和 login.html
HelloController类
package com.lulu;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("login")
public String goLogin() {
return "login";
}
}
Login.html页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>登陆成功</h1>
</body>
</html>
3. 错误代码
timestamp:时间戳
status:状态码
error:错误提示
exception:异常对象
message:异常消息
errors: JSR303数据校验的错误
5XX.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>5XX</title>
</head>
<body>
<h1>status:[[${status}]]</h1>
<h2>timestamp:[[${status}]]</h2>
<h2>exception:[[${exception}]]</h2>
<h2>message::[[${message}]]</h2>
</body>
</html>
4. 运行结果