thymleaf知識點總結

1.hymeleaf塊標籤(空標籤)th:block,標籤本身不顯示。
  如table 裏面tr->td
<th:block th:switch="${sales.operateMark}">
<td th:case="0" th:text="初始"/>
   <td th:case="1" th:text="新增"/>
   <td th:case="2" th:text="更新"/>
   <td th:case="3" th:text="刪除"/>
  </th:block>

2.thymeleaf判斷list是否爲空
不爲空:
th:if="${not #lists.isEmpty(listData)}"
爲空:
th:if="${#lists.isEmpty(listData)}"
3.一篇解決 thymeleaf 下拉選的選中問題
https://blog.csdn.net/qq_40925189/article/details/102818274?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

4.用thymeleaf用標籤給頁面select下拉框賦值
<div class="form-group">
    <label>性別</label> <select class="form-control" id="sex">
        <option value="1" th:selected="${sex=='1'}">男</option>
        <option value="2" th:selected="${sex=='2'}">女</option>
    </select>
</div>
5.thymeleaf-layout-dialect 有了這個佈局框架,你可以專注於body體的內容,不在糾結與left  header footer 公共js css
6.thymeleaf中th:attr多屬性
使用thymeleafa時候如果要hidden某些數據,我們可以使用th:attr 將數據作爲html標籤的一個屬性存起來

例如:       

<div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}" th:text="${cityName}">上海
   <span class="fa fa-angle-down"></span>
</div>
其中的 cityId是我們要保存起來的數據,然後就可以在js裏面使用了。
使用方式爲: 
 var cityId = $("#cityBtn").data("cityid");
 如果是有多個屬性要hidden,只需要用逗號隔開就可以了:
<div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}, data-regionId=${regionId}" th:text="${cityName}"" >上海
    <span class="fa fa-angle-down"></span>
 </div>
 

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