thymeleaf 常用标签

1、spring boot 集成 thymeleaf 

在pom.xml 文件中添加:

<!--引入thymeleaf的依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

项目目录结构

x

2、thymeleaf 常用标签

一:th:each

<option th:each="zjCategory:${zjCategoryDOs}" th:value="${zjCategory.id}" th:text="${zjCategory.name}"></option>

 

二:th:if  (如果不满足条件,该标签整个都不会显示)

<span th:if="${zjReply.delFlag==1}" th:text="有效" class="label label-primary"></span>
<span th:if="${zjReply.delFlag==0}" th:text="无效" class="label label-warning"></span>

三:th:onclick(点击事件)

<a th:onclick="${'updateDelFlag('+zjReplyChilds.id+',0)'}">下架</a>
<a th:onclick="${'updateDelFlag('+zjReplyChilds.id+',1)'}">上架</a>

四:th:href (语法:href="@{'/aa/${mode属性}'}")

<a th:href="@{'/zjcomment-q'+${queryType}+'-c-o-t.html'}">全部</a>

五:三元运算符 弥补 th:if  的 不足

作用:

在thymeleaf  中 没有

if(条件){

     

}

所以可以用 三元运算符。

         语法:${ a==1 ?'等于':'不等于'}

         例子: th:class="${#strings.isEmpty(category1)}?'active':''"  【#strings.isEmpty(category1)  判断category1 是否为"" 或者null】

   

六:th:block   运算块  

        可以让thymeleaf   不用写在元素上

 

七:th:include   包含代码块

<footer class="mt_40" th:include="zjcomment/page::footer"></footer>

【其中zjcomment 是包名     page 是文件名   footer  是代码块中 th:fragment="footer"】

 

八:th:attr  自定义属性

 <a th:attr="data-id=${'c'+zjCategory.id}" ></a>

九:thymeleaf 时间格式的显示

<th:block th:text="${zjcomment.createTime}==null?null:${#dates.format(zjcomment.createTime,'yyyy-MM-dd HH:mm')}"></th:block>

十:th:utext        富文本框内容显示网页中

<th:block th:utext="${zjcomment.context}"></th:block> 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wait_for_me

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值