thymeleaf中的判断总结

简介: thymeleaf中的判断总结

判断String字符串,添加引号

  th:class="${flag=='forum.html'}?'active'"

判断boolean类型,注意不能当成字符串处理,不能添加引号

  th:style="${session.simpleFlag==false}?'':'color:red'"

判断数字,注意不能直接使用小于号,会被当成html的元素标签,导致编译出错

  th:style="${pageNo}-3>0?'':'display: none'"

比较两个后台数据大小

  th:style="${sum}-1>${pageNo}?'':'display: none'"

判断是否等于null


 th:style="${session.dbUser==null}?'display:none;':'padding:0px 0px 0px 20px;'"


 th:unless="${sub.publishDate}==null"   或者  th:unless="${sub.publishDate==null}"   两种方法都行

多个判断,与运算符应使用转义字符


 th:if="${session.dbUser.user.face!=null && session.dbUser.user.face!=''}"



多个判断,或运算符应直接使用


 th:if="${session.dbUser.user.face==null || session.dbUser.user.face==''}"



三目运算符中使用到多个后台数据


 th:value="${topic == null} ? 'abc' : ${topic.title}"


 th:value="${item.id} == ${section.id} ? 'a' : ${item.b}"



用到的基本上就这些了,注意,三目运算符,获取session中的值等小问题



Javapub参考巨人:https://www.cnblogs.com/acm-bingzi/p/thymeleafJudge.html

目录
相关文章
|
1月前
|
Java Maven Spring
【Spring】EL表达式失效的问题(添加 isELIgnored)
【Spring】EL表达式失效的问题(添加 isELIgnored)
freemarker中对null值的处理
官方文档 ​​​​​​FreeMarker 中文官方参考手册 (foofun.cn)
|
7月前
|
XML Java 编译器
FreeMarker循环
FreeMarker循环
|
7月前
|
JavaScript 前端开发
Thymeleaf属性值详解
Thymeleaf属性值详解
|
7月前
thymeleaf if 条件判断
thymeleaf if 条件判断
thymeleaf 的 th:each 标签示例
thymeleaf 的 th:each 标签示例
103 0
|
存储 JSON 前端开发
Spring MVC【参数的获取与数据返回】
Spring MVC【参数的获取与数据返回】
Spring MVC【参数的获取与数据返回】
|
Java 数据库连接 mybatis
mybatis if标签字符串判断
mybatis if标签字符串判断
168 0
【Thymeleaf】thymeleaf中给input的value属性设置值
【Thymeleaf】thymeleaf中给input的value属性设置值
480 0
|
Java Spring
Spring Boot - Thymeleaf 表达式语法
Spring Boot - Thymeleaf 表达式语法
Spring Boot - Thymeleaf 表达式语法