Thymeleaf教程 (十) 屬性的優先級列表

當你在一個tag裏面定義多個屬性後。優先級就比較重要了。

<ul>
<li th:each="item : ${items}" th:text="${item.description}">Item description here...</li>
</ul>
  • 1
  • 2
  • 3

上述代碼必須先執行each,再執行text,否則就會出錯。爲了保證上述優先級,Thymeleaf給自己的屬性都定義了一個順序。

Thymeleaf的優先級定義是通過數字標記的升序來定義,這個順序是:

順序 功能 屬性
1 模塊包含 th:include,th:replace
2 模塊循環 th:each
3 條件判斷 th:if,th:unless,th:switch,th:case
4 局部變量 th:object,th:with
5 通用屬性修改 th:attr,th:attrprepend,th:attrappend
6 特殊屬性修改 th:value,th:href,th:src…
7 文本顯示 th:text,th:utext
8 模塊定義 th:fragment
9 模塊移除 th:remove

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