美文网首页错误日志
9.spring boot 自定义错误页面

9.spring boot 自定义错误页面

作者: 会灰的大飞狼 | 来源:发表于2017-04-28 10:43 被阅读261次

直接在templates目录下新建error.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Error Pages</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>错误页面:</h1>
<p th:text="'路径: ' + ${path}" />
<p th:text="'错误: ' + ${error}" />
<p th:text="'状态码: ' + ${status}" />
<p th:text="'异常类型: ' + ${exception}" />
<p th:text="'异常信息: ' + ${message}" />
<p th:text="'时间: ' + ${#dates.format(timestamp,'yyyy-MM-dd HH:mm:ss')}" />
</body>
</html>
image.png

就替换掉了默认的错误页面.里面的变量在DefaultErrorAttributes类里可以找到.
原理方面看下面这个帖子,写的很详细
http://www.open-open.com/lib/view/open1446607376779.html

相关文章

网友评论

    本文标题:9.spring boot 自定义错误页面

    本文链接:https://www.haomeiwen.com/subject/qxcnzttx.html