同计算机语言中各种操作符有优先级一样,类似的当同一个标签中有多个th:*属性时,Thymleaf在处理这些属性时也有优先级的问题。
<ul> <li th:each="item : ${items}" th:text="${item.description}">Item description here...</li> </ul>Thymleaf中定义的属性优先级,从上到下优先级越来越低
OrderFeatureAttributes1Fragment inclusionth:include th:replace2Fragment iterationth:each3Conditional evaluationth:if th:unless th:switch th:case4Local variable definitionth:object th:with5General attribute modificationth:attr th:attrprepend th:attrappend6Specific attribute modificationth:value th:href th:src …7Text (tag body modification)th:text th:utext8Fragment specificationth:fragment9Fragment removalth:remove因为不按书写顺序定义优先级,同一个标签中th:*属性书写顺序本身不会影响最终的执行结果,以下代码将和开头的代码有同样的输出。
<ul> <li th:text="${item.description}" th:each="item : ${items}">Item description here...</li> </ul>