【问题标题】:Conditional expressions in Thymeleaf text templateThymeleaf 文本模板中的条件表达式
【发布时间】:2019-10-29 16:27:46
【问题描述】:

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

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

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

【问题讨论】:

    标签: thymeleaf


    【解决方案1】:

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

    对我来说,这归结为一个看起来像这样的模板:

    [# 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 识别为大文档文件中的正确部分。

    【讨论】:

      猜你喜欢
      • 2019-12-31
      • 2017-04-06
      • 2015-02-22
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      相关资源
      最近更新 更多