没有 html 元素的 Thymeleaf 属性

Fed*_*ico 0 java thymeleaf

我所做的是使用 Thymeleaf 属性,但我不想拥有例如额外的 div。

例如,我有这个

<div sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</div>
Run Code Online (Sandbox Code Playgroud)

但我想要这样的东西:

<sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</>
Run Code Online (Sandbox Code Playgroud)

这可能吗?

And*_*rew 7

您可以使用th:block标签:

<th:block sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</th:block>
Run Code Online (Sandbox Code Playgroud)

来自 Thymeleaf 文档:

th:block 只是一个属性容器,它允许模板开发人员指定他们想要的任何属性。Thymeleaf 将执行这些属性,然后简单地使块消失得无影无踪。