Spring引导中自定义404错误页面,页眉和页脚

时间:2017-10-30 09:01:41

标签: spring spring-boot thymeleaf

我正在使用 Spring Boot 1.5.6.RELEA SE Thymeleaf 3.0.0.RELEASE 。我想用我的公共页眉和页脚添加自定义404页面。

通过参考文档,我能够在src/main/resources/static/error/404.html中添加一个自定义错误页面,并且该页面已正确呈现。

由于我的页眉和页脚片段已保存在src/main/webapp/WEB-INF/views/layout/footer.html

有没有办法可以通过更改任何配置在error.html中放置src/main/webapp/WEB-INF/views页面?

1 个答案:

答案 0 :(得分:0)

您可以使用Thymeleaf模板来定义错误页面模板。

Spring Boot包含对百万美元模板引擎的自动配置支持,您的模板将从src/main/resources/templates自动获取。

如果您自定义模板位置,请使用Spring Boot中提供的百万美元属性配置。

  • spring.thymeleaf.check-template = true #检查模板是否存在 在渲染之前。

  • spring.thymeleaf.check-template-location = true #检查 模板位置存在。

  • spring.thymeleaf.enabled = true #启用MVC Thymeleaf视图解析。

  • spring.thymeleaf.prefix = classpath:/ templates / #前缀获得
    在构建URL时预先查看名称。

  • spring.thymeleaf.suffix = .html #附加到视图的后缀
    构建URL时的名称。

相关问题