thymeleaf中的条件判断用法
来源:互联网 发布:外国人感叹淘宝 编辑:程序博客网 时间:2024/05/20 02:27
一.简单的条件:“if”和“unless”
th:if用法实例:
<table><tr><th>NAME</th><th>PRICE</th><th>IN STOCK</th><th>COMMENTS</th></tr><tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'"><td th:text="${prod.name}">Onions</td><td th:text="${prod.price}">2.41</td><td th:text="${prod.inStock}? #{true} : #{false}">yes</td><td><span th:text="${#lists.size(prod.comments)}">2</span> comment/s <a href="comments.html" th:href="@{/product/comments(prodId=${prod.id})}" th:if="${not #lists.isEmpty(prod.comments)}">view</a></td></tr></table>
如果值不是空:
1.如果一个布尔值,是true。
2.如果值是一个数字,非零 non-zero
3.如果是一个字符,非零值 non-zero
4.如果值是一个字符串,而不是“false”,“off” or “no”
5.如果值不是布尔,一个数字,一个字符或字符串。
(如果值是null,th:if将评估为false)。
th:unless用法:
<a href="comments.html" th:href="@{/comments(prodId=${prod.id})}" th:unless="${#lists.isEmpty(prod.comments)}">view</a>
二.switch用法:(th:switch
/ th:case)
<div th:switch="${user.role}"><p th:case="'admin'">User is an administrator</p><p th:case="#{roles.manager}">User is a manager</p></div>
被指定为默认选项用th:case="*";相当于default,例如:
<div th:switch="${user.role}"><p th:case="'admin'">User is an administrator</p><p th:case="#{roles.manager}">User is a manager</p><p th:case="*">User is some other thing</p></div>
0 0
- thymeleaf中的条件判断用法
- Thymeleaf条件判断
- Thymeleaf教程 (七) 条件表达式用法
- 条件表达式-Thymeleaf常见用法(五)
- Thymeleaf教程 (七) 条件表达式用法
- thymeleaf中的th:each用法
- thymeleaf中的th:assert用法
- thymeleaf中的th:remove用法
- 条件判断用法
- themeleaf中的th:switch条件判断语句用法示例
- SQL中的条件判断语句(case when zhen)用法
- makefile中的条件判断
- shell中的条件判断
- Python中的条件判断
- 条件判断中的真假
- python中的条件判断
- thymeleaf条件表达式
- linux shell中的条件判断
- thymeleaf中的th:each用法
- java List的使用
- java中split()特殊符号"." "|" "*" "\" "]"
- 布局xml文件中的include标签
- 最小生成树的prim算法
- thymeleaf中的条件判断用法
- Mac上安装MySQL记要
- yii2中,视图中使用autocomplete在传值和显示在两个不同的表的时候,进行搜索查询的方法
- 大端模式与小端模式、网络字节顺序与主机字节顺序
- 重设SVN 的GNOME keyring [(null)] 的密码
- Java数据类型
- thymeleaf中的模板布局
- VM Linux 无法打开,无法上网
- java获取访问路径、域名、项目名、请求入参