【问题标题】:If condition inside thymeleaf-html is not working properly如果 thymeleaf-html 内的条件无法正常工作
【发布时间】:2014-05-27 07:43:51
【问题描述】:

这是百里香代码

这里 2 th:如果条件被检查并且网页中可见 2 个标题

这里我只想在网页中看到真正的条件语句标题

用户的值列表值

条件是有任何已登录的用户,标题为sellerhome,并且没有已登录的用户列表为空,因此主页标题显示在网页上

<div th:each="s,pStat : ${Users} "> 
<div th:if="${s ==null}"  th:unless="${pStat.index > 0}">
    <header  th:include="../templates/homeTemplate :: header" id="header">
    </header> 
</div> 
<div  th:else="${s != null} "  th:unless="${pStat.index > 0}" >
    <header th:include="../templates/SellerTemplate :: header" id="header">
    </header>
</div>
</div>

【问题讨论】:

  • 你应该尝试更好地表达自己,因为这个问题很难阅读:)
  • @geo 我知道,但我的语言很糟糕
  • 我明白,但人们可能无法弄清楚你想做什么:)

标签: html if-statement thymeleaf


【解决方案1】:

如果我正确理解了您要执行的操作,请使用以下代码:

<div th:if="${#lists.isEmpty(Users)}">
    <header  th:include="../templates/homeTemplate :: header" id="header">
    </header> 
</div> 
<div th:unless="${#lists.isEmpty(Users)}">
    <header th:include="../templates/SellerTemplate :: header" id="header">
    </header>
</div>

#lists 是一个 Thymeleaf 实用程序对象,其中包含用于处理列表的常用方法。 有关更多详细信息,请参阅Thymeleaf 文档中的“表达式实用程序对象”部分。

还要注意lists.isEmpty 会检查列表是否为空或空,因此无需进行空检查即可保存使用

【讨论】:

  • 嗨,它正在工作,但我想知道值列表来自哪里?
  • 我将列表更改为布尔值问题在这里stackoverflow.com/questions/23903277/… 这工作正常,但我希望这种情况在另一个地方请帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 2022-01-22
相关资源
最近更新 更多