使用Spring和Thymeleaf过滤html内容

使用Spring和Thymeleaf过滤html内容,spring,spring-security,thymeleaf,spring-boot,Spring,Spring Security,Thymeleaf,Spring Boot,如何通过使用Spring引导和Spring Security以及Thymeleaf根据身份验证状态过滤html内容? 注意:我使用的是Spring boot自动配置。使用Thymeleaf的Spring安全集成可以实现您想要的功能(如果您还没有集成这两个功能,请查看此项) 例如,您可以执行以下操作: <div sec:authorize="hasRole('ROLE_ADMIN')"> This content is only shown to administrators.

如何通过使用Spring引导和Spring Security以及Thymeleaf根据身份验证状态过滤html内容?
注意:我使用的是Spring boot自动配置。

使用Thymeleaf的Spring安全集成可以实现您想要的功能(如果您还没有集成这两个功能,请查看此项)

例如,您可以执行以下操作:

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

此内容仅显示给管理员。
此内容仅向用户显示。

过滤html内容的确切含义是什么?您的意思是希望仅当用户具有特定角色时才呈现html的某些部分吗?是的,例如登录按钮和注销按钮。此解决方案不起作用:模板引擎不呈现“sec”关键字(并且自动配置默认允许使用安全方言)。您是否已将xmlns:sec=”“添加到html标记中?如果是,您是否执行了上面链接中提到的集成步骤?你得到的堆栈跟踪是什么?什么都没有。当我检查页面的源代码时,我可以看到“sec”标记。