Thymeleaf - boolean operators(Thymeleaf - 布尔运算符)
问题描述
如何使用 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 - 布尔运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Thymeleaf - 布尔运算符


基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01