thymeleaf 使用手冊

thymeleaf 是一個標籤語言,類似於c標籤,下面實際工作舉例,列舉常用規則說明:

【1】輸入框中顯示用戶姓名。

姓名:<input type="text" name="name" th:value="${user.name}">

【2】下拉選擇月份 :其中monthList爲月份數據,th:field爲回顯數據(這裏回顯值爲query對象中的mid屬性)。

<span>月份:</span>
<select name="mid" th:field="${query.mid}">
    <option th:each="each : ${monthList}" th:text="${each.name}"  th:value="${monthList.id}"></option>
</select>

【3】鏈接

  • 第一個鏈接爲顯示用戶姓名,點擊姓名會自動跳轉到用戶詳情頁面,這裏後面會攜帶一個id參數。
  • 第二個爲用戶點擊自己的詳情頁面,不攜帶參數(id後臺session中獲取)。 
<a th:href="@{/user/detail(id=${user.id})}"  th:text="${user.name}"></a>
<a th:href="@{'/system/dis/user/detail'}">個人詳情</a>

 【4】判斷條件:只有當用戶狀態爲2時,才支持編輯操作。

<a th:unless="${user.status==2}">編輯</a>

【5】循環:展示用戶列表 。

<table>
    <tr>
        <th width="20%">姓名</th>
        <th width="10%">年齡</th>
        <th width="70%">地址</th>
    </tr>
    <tr th:each="user:${userList}">
        <td th:text="${user.name}"></td>
        <td th:text="${user.age}"></td>
        <td th:text="${user.address}"></td>
    </tr>
</table>

【6】 頁面引用:引用工程system文件夾下的page.html文件。

<div th:replace="system/page"></div>

【7】時間格式化:格式化後臺Date類型字段createTime,顯示爲 yyyy-MM-dd 日期格式。

創建時間:<input type="text" th:value="${#calendars.format(batch.createTime,'yyyy-MM-dd')}">

【8】拼接:用兩條豎線包起來,裏面可以隨意拼接 

<a th:onclick="|deleteById('${user.id}')|">刪除</a>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章