springboot2.1.2+springsecurity5.1.3+thymeleaf3.0.11 sec标签不生效

在学习springsecurity时候,标签sec没有生效,也没有报错。如下语句无法正常使用

<div sec:authorize="isAuthenticated()">
  This content is only shown to authenticated users.
</div>
<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>

查阅thymeleaf示例,也没说引入sec标签只是给了几个例子,见https://www.thymeleaf.org/doc/articles/springsecurity.html,查了好久,加入Thymeleaf Extras Springsecurity4,如这篇文http://auan.cn/java/1654.html

  1. 通过查阅mvnrepository发现有Thymeleaf Extras Springsecurity5
  2. 在pom加入https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity5
  3. html文件中的sec还是用4的
    <html xmlns:th="http://www.thymeleaf.org"
          xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
  4. 亲测有效

 

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值