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