条件表达式-Thymeleaf常见用法(五)

xiaoxiao2021-02-28  153

条件表达式

if

th:if

th:if=“ ${not #lists.isEmpty(prod.comments)}”

thymeleaf表达式,不单单是判断是否为true,可以分为如下类型判断:

如果值不为null,有以下情况,认为条件成立:

如果是boolean,值为true如果是number,值不为0如果是字符,值不为0如果是字符串,值不为” FALSE” ,” off” ,” no”如果值不是boolean,或number,或者字符,或字符串

th:if还有一个相反的用法: th:unless

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>

默认的情况

The default option is specified as th:case=“ *” :

转载请注明原文地址: https://www.6miu.com/read-25299.html

最新回复(0)