(转)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中的值等小问题

转自:

阿丙的博客园

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