如何使用 Thymeleaf 使用布尔运算符,如 and
或 or
?
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 - 布尔运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!