码迷,mamicode.com
首页 > 其他好文 > 详细

(转)thymeleaf中的判断总结

时间:2018-07-03 20:11:29      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:使用   http   als   htm   方法   三目运算符   ref   基本   val   

 判断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中的值等小问题

转自:

阿丙的博客园

(转)thymeleaf中的判断总结

标签:使用   http   als   htm   方法   三目运算符   ref   基本   val   

原文地址:https://www.cnblogs.com/SimonHu1993/p/9259841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!