thymeleaf - thymeleaf 的默认 else 语句 if case
问题描述
我知道我可以使用th:if
and th:unless
forif-else
条件 on thymeleaf
。但我想知道是否有任何其他方法可以在不使用th:unless
.
我有这样的条件
th:if="${not #lists.isEmpty(myList) and condition1 and condition2 and condition3}"
现在我不想在th:unless
块上重复相同的条件。有没有办法在不使用的情况下做到这一点th:unless
?
解决方案
不,没有办法做到这一点th:if
——它只影响一个标签。不过,还有几个更详细的选项:
根据您的条件使用
th:with
。例如:<th:block th:with="condition=${not #lists.isEmpty(myList) and condition1 and condition2 and condition3}"> <div th:if="${condition}" /> <div th:unless="${condition}" /> </th:block>
使用
th:switch
. 例如:<th:block th:switch="${not #lists.isEmpty(myList) and condition1 and condition2 and condition3}"> <div th:case="true" /> <div th:case="*" /> </th:block>
推荐阅读
- javascript - 从 javascript 更改 css 类
- typo3 - 如何在 TYPO3 的自定义扩展中以编程方式添加文件收集记录
- c# - C# 使用 Process.Start() 作为 cmd 和活动 RedirectStandardOutput 的参数执行应用程序
- java - 如何使用 AutoWired 将 spring bean 注入 ContainerRequestFilter?
- r - 集群验证参数
- angular2-forms - 以角度 2 更新对象的值
- javascript - 茉莉花测试中来自js文件的模拟函数
- excel - 在 IF 语句中使用 VLookup
- macos - 如何使用 Delphi 的 NSNotificationCenter 观察者?
- html - font-size 超过 20px 时浮动元素之间的间隙