本文主要是介绍进阶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@Beanpublic 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>
这篇关于进阶SpringBoot之 Shiro(6)整合 Thymeleaf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!