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




大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)