thymeleaf用法總結

做完了一個項目,把全部用到的thymeleaf的用法總結記錄一下,反正記是肯定記不住的,做個筆記方便以後查閱吧。

0.數據來源

在java後端添加到model中,根據鍵值對的鍵,在html文件裏面的讀取。

1.th:text

th:text="${question}"
<!--字符串與變量拼接-->
th:text="'截止時間:'+${date}"

2.th:if

th:if="${var1 != var2}"
th:if="${user.type == 1}"

3.th:each

<!-- 遍歷users(list) -->
th:each="user : ${users}"

4.三元運算符

th:text="${user.type==1?'管理員':'標註工人'}"

5.th:onclick

th:onclick="deleteUser([[${user.id}]]);"
th:onClick="|working(${projectId},${index+1},${taskId})|"

6.th:href

th:href="@{'/downloadExcel/'+${project.id}+'/'+${project.name}}"
th:href="@{/(page=${pageDTO.page+1})}"

7.th:style

th:style=" 'width:' + @{${project.progress}} +'%; height: 6px;' " th:aria-valuenow="${project.finishedCount}"

8.處理時間格式

th:text="${#dates.format(project.gmtCreate,'yyyy-MM-dd')}"
th:text="${#dates.format(project.deadline,'yyyy-MM-dd HH:mm')}"

9.th:class

th:class="'page-item ' + @{${pageDTO.page==page}?'active':''}"

 

發佈了28 篇原創文章 · 獲贊 134 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章