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 - 布尔运算符
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
