0

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

例如,我有这个

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

但我想要这样的东西:

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

这可能吗?

4

1 回答 1

7

您可以使用th:block标签:

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

来自 Thymeleaf 文档:

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

于 2015-08-31T16:08:28.133 回答