springboot错误页面放在templates下无法跳转

通过实现ErrorPageRegistrar接口,重写registerErrorPages方法配置错误页面跳转:

springboot错误页面放在templates下无法跳转

如果404.html错误页面放在templates包下,需要配置controller进行访问跳转

springboot错误页面放在templates下无法跳转

如果放在static包下,可以直接通过页面访问到。

在springboot项目中默认访问路径是static文件夹和template文件夹,static文件夹下的资源可以通过浏览器直接访问(如:localhost:8080/index.html,如有文件夹输入正确路径即可 如:localhost:8080/image/abc.jpg),而template文件夹下的页面需要在controller中跳转进行访问。在controller中如果直接return页面的名称那么默认从template文件夹中去寻找对应的页面