如何在Thymleaf模板中添加未包含在生成的HTML中的源代码注释?

pra*_*402 38 thymeleaf

我在一个中型Web应用程序中使用全栈Thymeleaf(spring mvc,security,layout dialect,webflow).

好的..现在我们在html模板中放了这么多代码,包含未包含在生成的HTML文件中的源代码注释会很不错.

我们如何实现这一目标?

Raf*_*iec 60

版本2.1已发布,所以现在您可以升级您的库并在代码中使用注释.使用此版本,开发人员可以使用解析器级注释块:

<!--/* This code will be removed at thymeleaf parsing time! */-->
Run Code Online (Sandbox Code Playgroud)

和原型评论块:

<span>hello!</span>
<!--/*/
    <div th:text="${...}">

</div>
/*/-->
<span>goodbye!</span>
Run Code Online (Sandbox Code Playgroud)

详细解释可以在这里的官方文档中找到:http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#comments-and-blocks

  • 请注意,&lt;!--/* 应该在 &lt;!-- 和 /* 之间没有空格。刚被咬了就想提一下。 (2认同)

ytt*_*rrr 6

正如前面提到的Rafal Borowiec评论你应该使用的HTML代码块

<!--/*评论*/-->构造的东西(见文档).

也可以使用百日咳来评论/删除您的JavaScript代码

/*[-评论-]*/构造的东西(见文档).因此,您可以在不泄漏任何信息的情况下注释您的js代码

/*[-
 *
 * Some information about function.
 *
 * -]*/
function someFunction() {
    console.log('Hello world');
}
Run Code Online (Sandbox Code Playgroud)


pet*_*ica 5

使用 Thymeleaf 3.0,当前的工作版本是

<!--/*-->
   this comment will be removed by thymeleaf on the template processing
<!--*/-->
Run Code Online (Sandbox Code Playgroud)

对于早期的 thymeleaf 版本,其他答案对我不起作用。当前 thymeleaf 文档在这里


mic*_*man 2

在当前稳定版本的 Thymeleaf 中这是不可能的。正如Thymeleaf Issue 10中提到的,计划发布 2.1 版本