本文介绍了Thymeleaf-布尔运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Thymeleaf使用像andor这样的布尔运算符?

How can I use boolean operators like and or or using Thymeleaf?

例如,如果只有一个条件为真,我想显示表中的数据.

For instance, if I want to show the data from a table if only one of the conditions is true.

<tr th:if="firstCondition or secondCondition">
  <td th:text="${entity.attr1}"</td>
  <td th:text="${entity.attr2}">Default Value</td>
</tr>

推荐答案

布尔运算符就是这样工作的.您使用或",和"而不是常规的Java命名法.您还可以缩短ifs.

Boolean operators work just like that. You use 'or', 'and' instead of the normal java nomenclature. You can also shorten your ifs.

您可以尝试以下操作:

<tr th:if="${violation.remainingDebt != 0 or violation.validity}">

如果考虑到测试的逻辑或"操作是孤立的,则需要将它们单独嵌套在相同的大括号中.

You need to nest them up in the same curly brackets, independently if they are isolated considering the logical 'or' operation being tested.

但是要小心!如果if传递为true,则只会向您显示tr及其子元素.

Be wary though! This will only show you the tr and it's child elements if the if passes as true.

这篇关于Thymeleaf-布尔运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 01:00
查看更多