Thymeleaf 教程

Thymeleaf 注释和块

标准 HTML/XML 注释

标准的 HTML/XML 注释 <!-- ... --> 可以在 Thymeleaf 模板的任何地方使用。这些注释中的内容不会被 Thymeleaf 处理,而是逐字复制到结果中。

<!-- User info follows -->
<div th:text="${...}">
    ...
</div>

Thymeleaf 解析器级注释块

解析器级别的注释块是代码,当 Thymeleaf 解析它时,它将被简单地从模板中删除。它们看起来像这样:

<!--/* This code will be removed at Thymeleaf parsing time! */-->

Thymeleaf 会删除 <!--/* 和 */--> 之间的所有内容,所以这些注释块也可以用来在模板静态打开时显示代码,因为知道在 Thymeleaf 处理它时它会被删除。

<!--/*--> 
<div>
    you can see me only before Thymeleaf processes me!
</div>
<!--*/-->

例如,这对于有大量 <tr> 的表格原型设计来说,可能非常方便:

<table>
    <tr th:each="x : ${xs}">
        ...
    </tr>
    <!--/*-->
    <tr>
        ...
    </tr>
    <tr>
        ...
    </tr>
    <!--*/-->
</table>
说说我的看法
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号