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 - 布尔运算符


基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01