1、引入依赖
<!--thymeleaf中使用shiro-->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
2、ShiroConfig中编写shiroDialect
@Bean(name = "shiroDialect")
public ShiroDialect shiroDialect(){
return new ShiroDialect();
}
3、html页面添加xmlns
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
4、在标签中使用shiro标签
<div shiro:hasPermission="add">
<a href="/1">1111</a>
</div>
<div shiro:hasPermission="update">
<a href="/2">2222</a>
</div>
<div shiro:hasPermission="all">
<a href="/1">1111</a>
<a href="/2">2222</a>
</div>
注:根据不同权限某些功能进行隐藏和展示:
如:admin账号具有最大权限,则可以看到所有功能

zhangsan具有修改权限,则只能看到修改按钮

lisi具有增加权限,则只能看到增加按钮
本文介绍如何在Thymeleaf模板中集成Shiro进行权限控制,包括依赖引入、配置ShiroDialect、HTML页面的xmlns声明及使用shiro标签实现不同权限下功能的展示与隐藏。
353

被折叠的 条评论
为什么被折叠?



