6.1 Spring Boot异常处理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16855077/article/details/84972810

spring boot异常分为5钟

1.自定义异常页面

spring boot默认有一套处理异常的机制,出现异常后默认会发送/error请求,如果我们需要自定义页面展示异常,可以在templates目录下新建error页面

 error.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>错误提示页面</title>
</head>
<body>
出错了,请与管理员联系。。。
<span th:text="${exception}"></span>
</body>
</html>

该url的请求找不到,404错误,跳转到我们自定义的异常页面去了。 

分析:这种方法不建议采用,没有对异常进行细分。

 

猜你喜欢

转载自blog.csdn.net/qq_16855077/article/details/84972810