thymeleaf - Thymeleaf 文本模板中的条件表达式

标签 thymeleaf

不知何故,我不理解 thymeleaf 文本模板语法背后的概念。从我的 html 模板中我知道这样的代码:

<div th:if="${#lists.isEmpty(foreign)}">
<div th:unless="${#lists.isEmpty(foreign)}">

我了解到 ${variable} 需要重写为 [(${variable})] 因为否则它不会被识别,因此不会被替换。但是我需要如何编写 if 和其他条件表达式呢? 看着docs对我帮助不大。

最佳答案

我为自己的问题提供这个答案,因为我认为其他人在寻找正确的链接时可能也会遇到同样的问题。我正在寻找的信息可以在 https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html 找到。在第 4.1 章中。

对我来说,这可以归结为一个如下所示的模板:

[# th:unless="@{#lists.isEmpty(foo1list)}"]
  OR Foo1 IS IN ( @{foo1List} )
[/]
[# th:unless="@{#lists.isEmpty(foo2list)}"]
  OR Foo2 IS IN ( @{foo2List} )
[/]
[# th:unless="@{#lists.isEmpty(foo3list)}"]
  OR Foo3 IS IN ( @{foo3List} )
[/]

在迁移指南中找到此语法后,我能够识别 this作为大文档文件中的正确部分。

关于thymeleaf - Thymeleaf 文本模板中的条件表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58611656/

相关文章:

css - .css 文件中的 Thymeleaf URL 表达式

spring-boot - 如何在 Thymeleaf 中创建动态表 ..?

java - 为什么在 Controller 中使用 @GetMapping 而不是 @DeleteMapping 进行删除工作?

mysql - 如何在 Spring Boot 中使用 Thymeleaf 保存角色?

java - Spring资源返回空白html页面

spring-boot - Thymeleaf 如何为 Google Chart 输出对象数组

java - 包含 springboot 和 thymeleaf 的列表

java - 基于 Controller 的错误页面 spring thymeleaf

java - Thymeleaf 页面布局标题属性被覆盖

java - 如何使用 thymeleaf 在具有动态列的数据表中显示输入值