Thymeleaf属性没有html元素

时间:2013-05-13 15:30:40

标签: java thymeleaf

我所做的是使用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. 
</>

这可能吗?

1 个答案:

答案 0 :(得分:3)

您可以使用th:block标记:

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

来自Thymeleaf docs:

  

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