java - 如果/否则在 thymeleaf 中

标签 java spring thymeleaf

在 thymeleaf 中是否有更好的方法来执行以下操作?

<div th:if="${status} == 404">
    Special display for 404 page!
</div>

<div th:if="${status} != 404">
    Not a 404 page!
</div>

例如,在 django 中,它很简单:

{% if status == 404 %}
    Special display for 404 page!
{% else %}
    Not a 404 page!
{% endif %}

最佳答案

来自文档:

Thymeleaf's main goal is to bring elegant natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams.

所以这种类似 HTML 的语法是有意为之的,没有“更简单”的语法。

另请参阅How to do if-else in Thymeleaf?一些替代方案。

关于java - 如果/否则在 thymeleaf 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51550251/

相关文章:

Spring Web Reactive Framework 多部分文件问题

java - 使用 Thymeleaf 作为模板的 Spring Boot 发送电子邮件 - 配置不起作用

java - Thymeleaf 片段在方法执行之前加载

java - 反转整数数组

java - 帮助在 Linux 上启动 Java 应用程序

Java做while循环递增

spring - 反向代理后面的 Thymeleaf 模板(在 Spring 引导应用程序中)未正确形成 url

java - 有条件地向 Java 8 流添加操作

java - 登录 ADFS 时出现错误 - System.FormatException : Index (zero based) must be greater than or equal to zero and less than the size

java - 使用 @ModelAttribute 时未显示自定义域对象