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

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