【shiro基础】springboot + shiro整合thymeleaf
目录
- 写在前面
- 引入依赖
- 配置方言
- 页面引入
- 页面样例
- 使用说明
- 附
写在前面
本文基于【shiro基础】springboot整合shiro 进行整合。
引入依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>2.6.3</version></dependency><dependency><groupId>com.github.theborakompanioni</groupId><artifactId>thymeleaf-extras-shiro</artifactId><version>2.1.0</version></dependency>
配置方言
配置方言,使shiro能在thymeleaf中引入使用
/*** 整合thymeleaf*/@Beanpublic ShiroDialect shiroDialect(){return new ShiroDialect();}
页面引入
分别引入thymeleaf及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>
</head>
<body><div th:if="${session.user == null}"><h2>登录</h2><form th:action="@{/auth/sublogin}"><input name="userName"><input name="password" type="password"><input type="submit" value="登录"></form>
</div>
<hr>
<div th:if="${session.user != null}"><h2 th:text="${session.user.username}"></h2><a th:href="@{/auth/logout}">退出登录</a> <div shiro:hasPermission="demo:p1"><a th:href="@{/demo/p1}">p1</a> </div><div shiro:hasPermission="demo:p2"><a th:href="@{/demo/p2}">p2</a></div>
</div>
</body>
</html>
使用说明
使用示例 | 说明 |
---|---|
<shiro:authenticated> | 已登录 |
<shiro:notAuthenticated> | 未登录 |
<shiro:guest> | 用户在没有RememberMe时 |
<shiro:user> | 用户在RememberMe时 |
<shiro:hasAnyRoles name=“abc,123” > | 在有abc或者123角色时 |
<shiro:hasRole name=“abc”> | 拥有角色abc |
<shiro:lacksRole name=“abc”> | 没有角色abc |
<shiro:hasPermission name=“abc”> | 拥有权限资源abc |
<shiro:lacksPermission name=“abc”> | 没有abc权限资源 |
<shiro:principal> | 显示用户身份名称 |
附
完整源代码
【shiro基础】springboot + shiro整合thymeleaf相关推荐
- 【Springboot】SpringBoot基础知识及整合Thymeleaf模板引擎
文章目录 SpringBoot简介 SpringBoot是什么 为什么要学习SpringBoot SpringBoot的优势 学习SpringBoot前要具备的基础 创建第一个SpringBoot项目 ...
- SpringBoot中整合Thymeleaf
场景 springboot不建议使用jsp,使用模板引擎,比如thymeleaf,velocity,freemarker. 项目搭建专栏: https://blog.csdn.net/BADAO_LI ...
- 【SpringBoot】3、SpringBoot中整合Thymeleaf模板引擎
SpringBoot 为我们提供了 Thymeleaf 自动化配置解决方案,所以我们在 SpringBoot 中使用 Thymeleaf 非常方便 一.简介 Thymeleaf是一个流行的模板引擎,该 ...
- springboot shiro ajax,SpringBoot Shiro 登录成功后返回json数据 shiro使用ajax登录
老规矩,先上代码: protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletReques ...
- SpringBoot——整合数据库,springSecurity,shiro、整合thymeleaf
一.springboot--JDBC 狂神说SpringBoot07:整合JDBC 1.引入web.JDBC API.mysql Driver <dependency><groupI ...
- Spring Boot 综合示例-整合thymeleaf、mybatis、shiro、logging、cache开发一个文章发布管理系统...
一.概述 经过HelloWorld示例(Spring Boot 快速入门(上)HelloWorld示例)( Spring Boot 快速入门 详解 HelloWorld示例详解)两篇的学习和练习,相 ...
- Shiro与SpringBoot整合,实现登录拦截、用户认证、用户授权等。实战demo
文章目录 开篇必读: 一.开发环境 二.项目搭建 三.配置 shiro 配置类 1.自定义 Realm 类. 2.创建shiro配置类. 四.创建页面.Controller. Service等. 五. ...
- Shiro 入门笔记,整合SpringBoot,Redis
Shiro 入门笔记 视频地址:https://www.bilibili.com/video/BV1uz4y197Zm 感谢编程不良人的教程 1. 权限管理 权限管理包括用户 身份认证 和 授权 两部 ...
- Day374.shiro授权Shiro+jsp整合Springboot -Shiro
Shiro授权 一.授权 授权,即访问控制,控制谁能访问哪些资源.主体进行身份认证后需要分配权限方可访问系统的资源,对于某些资源没有权限是无法访问的. 二.关键对象 授权可简单理解为who对what( ...
- Springboot -Shiro整合JWT(注解形式)
Springboot -Shiro整合JWT(注解形式) 在这里只展示核心代码,具体的请访问github 参考timo 依赖导入 <dependencies><dependency& ...
最新文章
- 更改eclipse的Package Explorer的字体
- 无边框窗体的移动(winform/wpf)
- 中国在线英语培训行业投资热点分析与需求前景预测报告2022版
- JSON是什么?如何产生的?
- 升级浏览器_微软IE11浏览器 最后的升级机会
- 两本电子书 |Flink 最佳学习实践 | 从 0 到 1 学会 Apache Flink
- CentOS7下初始化PostgreSQL
- easyExcel 处理ExcelDataConvertException异常,获取异常的数据行列值等信息
- python中使用动量交易策略
- svn安装以及初步使用
- 计算机系毕业论文绪论,本科毕业论文绪论范文
- php超小免杀大马_php大马免杀技巧 | bypass waf
- 图文配置docker阿里云加速器教程
- 二进制和十进制的相互转换
- 获取当天零点/最晚时间戳
- android aar组件化,android module解耦组件化总体概述(推荐)
- Mysql查询当天,本周,本月所有数据记录
- 处理团队人际关系的九大原则
- 微信小程序vant 输入框问题
- Flutter的isolate异步线程机制及使用实战详解