thymeleaf中的几个注意点

String字符串,添加引号

  th:class="${flag=='XXX'} ? 'active' "

 

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

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

       th:if="${session.flg} == #{ERROR}"

 

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

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

 

比较大小

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

 

判空

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

  th:unless="${session.flg}==null"   或者  th:unless="${session.flg==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}"

ForEach

<table>
    <tr data-th-each="user : ${users}">
        <td data-th-text="${user.login}">...</td>
        <td data-th-text="${user.name}">...</td>
    </tr>
</table>

 

Switch

<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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值