【问题标题】:Custom error page using Thymeleaf使用 Thymeleaf 的自定义错误页面
【发布时间】:2016-11-09 15:36:20
【问题描述】:

我正在向 Spring Boot 项目添加自定义错误页面,我很好奇除了创建一个新的 error.html 页面之外,我是否需要做任何其他事情。

我显然希望页面针对不同的消息进行更改。但我注意到(偶然)<h1 th:text="#{error.status_code}">404</h1> 之类的东西返回给我??error.status_code_en_US??。我假设是 status_code 但不是以可读的方式或其他方式?是否有可能仅从 error.html 页面中获取?

还有一些……

<p  th:text="#{error.exception}">Default Error Message</p>
<p  th:text="#{error.exception_type}">Default Error Message</p>
<p  th:text="#{error.request_uri}">Default Error Message</p>
<p  th:text="#{error.servlet_name}">Default Error Message</p>

生成:

??error.exception_en_US??
??error.exception_type_en_US??
??error.request_uri_en_US??
??error.servlet_name_en_US??

【问题讨论】:

    标签: html spring spring-boot thymeleaf


    【解决方案1】:

    #{} 引用 i18n 实现并尝试从您的消息包中解析给定的字符串。要使用 SpringEL 进行评估,您必须使用 ${}

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 2015-06-22
      • 1970-01-01
      相关资源
      最近更新 更多