导包
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
在ShiroConfig中添加ShiroDialect的bean
@Bean
public ShiroDialect getShiroDialect(){
return new ShiroDialect();
}
在index.html中使用
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p th:text="${msg}"></p>
<!--判断是否存在已登录用户-->
<div th:if="${session.loginUser == null}">
<a th:href="@{/toLogin}">登录</a>
</div>
<hr>
<!--拥有user:add权限时显示-->
<div shiro:hasPermission="user:add">
<a th:href="@{/user/add}">add</a><br>
</div>
<!--拥有user:update权限时显示-->
<div shiro:hasPermission="user:update">
<a th:href="@{/user/update}">update</a>
</div>
</body>
</html>