进阶SpringBoot之 Shiro(6)整合 Thymeleaf
Subject:用户
SecurityManager:管理所有用户
Realm:连接数据
pom.xml 导入 thymeleaf-extras-shiro 的 jar 包,整合 shiro-thymeleaf
<!-- shiro-thymeleaf 整合 -->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.1.0</version>
</dependency>
ShiroConfig 配置类:ShiroDialect
//ShiroDialect:整合shiro-thymeleaf
@Bean
public ShiroDialect getShiroDialect(){
return new ShiroDialect();
}
index.html:
xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro"
<!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>
<shiro:guest>
<h1>首页</h1>
<p><a th:href="@{/toLogin}">登录</a></p>
<p th:text="${msg}"></p>
<hr>
<div shiro:hasPermission="user:add">
<a th:href="@{/user/add}">add</a>
</div>
<div shiro:hasPermission="user:update">
<a th:href="@{/user/update}">update</a>
</div>
</shiro:guest>
</body>
</html>