Spring boot支持以下几种自动配置404,500,等错误页面的方式
本次在项目中使用了模版引擎
1.只需在template目录下放入error.html,发生404,500等错误时就会统一跳转到error.html。
2.如果我们想发生404,500错误跳转到不同的错误页面的话,在template目录下追加error文件夹,
根据不同的应答code,命名不同的错误页面。
例: /template/error/404.html
/template/error/403.html
/template/error/500.html
3.如果想4开头的一类错误跳转到同一画面,5开头的一类错误跳转到另一画面,参照如下配置
例: /template/error/4xx.html
/template/error/5xx.html
注:如果没有使用模版引擎,直接放在static目录下即可。
有时候利用框架的一些配置,可以达到事半功倍的效果,少写一些代码,与大家分享。