4. 注釋
模板名稱:comment.html
4.1 標准 HTML/XML注釋
語法:<!-- -->
4.2 解析器級注釋塊(Parser-level comment blocks)
語法:<!--/* */-->
thymeleaf解析時會移除代碼
<!--/*--> <div> you can see me only before Thymeleaf processes me! </div> <!--*/-->
單行:<!--/* xxxxx */-->
雙行:
<!--/*-->
Xxxxxx
Xxxxxx
<!--*/-->
4.3 針對原型的注釋
語法:<!--/*/ /*/-->
<span>hello!</span> <!--/*/ <div th:text="${...}"> ... </div> /*/--> <span>goodbye!</span>
thymealeaf解析時會移除掉此標簽對,但不會移除其中的內容。
解析完成:
<span>hello!</span> <div th:text="${...}"> ... </div> <span>goodbye!</span>
4.4 與th:block結合
thymealeaf解析時會移除掉此標簽對,但不會移除其中的內容。
th:block
是一個屬性容器,允許模板開發人員指定他們想要的任何屬性。Thymeleaf將執行這些屬性,然后簡單地制作塊,而不是其內容消失。
<table> <th:block th:each="user : ${users}"> <tr> <td th:text="${user.login}">...</td> <td th:text="${user.name}">...</td> </tr> <tr> <td colspan="2" th:text="${user.address}">...</td> </tr> </th:block> </table>
<table> <!--/*/ <th:block th:each="user : ${users}"> /*/--> <tr> <td th:text="${user.login}">...</td> <td th:text="${user.name}">...</td> </tr> <tr> <td colspan="2" th:text="${user.address}">...</td> </tr> <!--/*/ </th:block> /*/--> </table>
view this:
<div> <ol> <li>解釋器級注釋塊(thymeleaf解析時會移除掉注釋塊所有代碼): <!--/* this is content! */--> </li> <li>針對原型的注釋(thymeleaf解析時會移除掉注釋標簽,但保留標簽內的內容): <!--/*/ this is content! /*/--> </li> <li>與th:block結合(thymeleaf解析時會移除掉th:block注釋塊,但保留標簽內的內容): <!--/*/<th:block th:each="user:${list}">/*/--> <div th:text="${user.userName}"></div> <!--/*/</th:block>/*/--> </li> </ol> </div>