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具有增加權限,則只能看到增加按鈕