【thymeleaf 】在 thymeleaf 中使用 shiro 标签
生活随笔
收集整理的這篇文章主要介紹了
【thymeleaf 】在 thymeleaf 中使用 shiro 标签
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言
- sprint boot 2.3.4.RELEASE
說明
shiro 未提供對 thymeleaf 的支持。第三方項目 thymeleaf-extras-shiro 提供了在 thymeleaf 上使用 shiro 標簽的能力。
A Thymeleaf dialect for Apache Shiro tags.
thymeleaf-extras-shiro
github
https://github.com/theborakompanioni/thymeleaf-extras-shiro
Maven
<dependency><groupId>com.github.theborakompanioni</groupId><artifactId>thymeleaf-extras-shiro</artifactId><!-- 目前最新版為2.0.0 --><version>${thymeleaf-shiro.version}</version> </dependency>示例
<!DOCTYPE html> <html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"><head><title>thymeleaf-extras-shiro</title></head><body><p shiro:guest="">Please <a href="login.html">login</a></p><p shiro:authenticated="">Hello, <span shiro:principal=""></span>, how are you today?</p></body></html>輸出用戶昵稱
<shiro:principal property="nickname" />還可以這么寫:
<th:block shiro:principal="" property="nickname" />還可以這么寫:
<span shiro:principal="" property="nickname" />標簽說明
Apache Shiro tags :
- https://shiro.apache.org/jsp-tag-library.html
- https://github.com/apache/shiro/blob/main/web/src/main/resources/META-INF/shiro.tld
| shiro:principal | 當前用戶的登錄信息,用戶名之類 |
| shiro:guest="" | 驗證是否是游客,即未認證的用戶 |
| shiro:user="" | 驗證是否是已認證或已記住用戶 |
| shiro:authenticated="" | 驗證是否是已認證用戶,不包括已記住用戶 |
| shiro:notAuthenticated= “” | 未認證用戶,但是 已記住用戶 |
| shiro:lacksRole=“admin” | 表示沒有 admin 角色的用戶 |
| shiro:hasAllRoles=“admin, user1” | 表示需要同時擁有兩種角色 |
| shiro:hasAnyRoles=“admin, user1” | 表示 擁有其中一個角色即可 |
| shiro:lacksPermission=“admin:delete” | 類似于 shiro:lacksRole |
| shiro:hasAllPermissions=“admin:delete, admin:edit” | 類似于 shiro:hasAllRoles |
| shiro:hasAnyPermission=“admin:delete, admin:edit” | 類似于 hasAnyRoles |
總結
以上是生活随笔為你收集整理的【thymeleaf 】在 thymeleaf 中使用 shiro 标签的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 设置 table name
- 下一篇: Netflix 动画《巫师:深渊海妖》先