首先需要导入thymeleaf对shiro扩展的坐标
<!-- https://mvnrepository.com/artifact/com.github.theborakompanioni/thymeleaf-extras-shiro -->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
配置shiroDialect,用于thymeleaf和shiro标签配合使用
/**
* 配置一个shirodialect 用户thymeleaf和shiro标签配合使用
*/
@Bean
public ShiroDialect getShiroDialect() {
return new ShiroDialect();
}
在页面上使用shiro的标签
<h1 th:text="${msg}"></h1>
<div shiro:hasPermission="user:add">
用户增加:<a href="useradd">用户添加</a>
</div>
<div shiro:hasPermission="user:update">
用户更新:<a href="userupdata">用户更新</a>
</div>
用于有相应的权限 才会显示 要是用户没有哪一个权限的话就不会出现