同计算机语言中各种操作符有优先级一样,类似的当同一个标签中有多个th:*属性时,Thymleaf在处理这些属性时也有优先级的问题。
<ul>
<li th:each="item : ${items}" th:text="${item.description}">Item description here...</li>
</ul>
Thymleaf中定义的属性优先级,从上到下优先级越来越低
Order | Feature | Attributes |
---|---|---|
1 | Fragment inclusion | th:include th:replace |
2 | Fragment iteration | th:each |
3 | Conditional evaluation | th:if th:unless th:switch th:case |
4 | Local variable definition | th:object th:with |
5 | General attribute modification | th:attr th:attrprepend th:attrappend |
6 | Specific attribute modification | th:value th:href th:src … |
7 | Text (tag body modification) | th:text th:utext |
8 | Fragment specification | th:fragment |
9 | Fragment removal | th:remove |
因为不按书写顺序定义优先级,同一个标签中th:*属性书写顺序本身不会影响最终的执行结果,以下代码将和开头的代码有同样的输出。
<ul>
<li th:text="${item.description}" th:each="item : ${items}">Item description here...</li>
</ul>