目录

  • 写在前面
  • 引入依赖
  • 配置方言
  • 页面引入
    • 页面样例
    • 使用说明

写在前面

本文基于【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> &nbsp;<div shiro:hasPermission="demo:p1"><a th:href="@{/demo/p1}">p1</a> &nbsp;</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相关推荐

  1. 【Springboot】SpringBoot基础知识及整合Thymeleaf模板引擎

    文章目录 SpringBoot简介 SpringBoot是什么 为什么要学习SpringBoot SpringBoot的优势 学习SpringBoot前要具备的基础 创建第一个SpringBoot项目 ...

  2. SpringBoot中整合Thymeleaf

    场景 springboot不建议使用jsp,使用模板引擎,比如thymeleaf,velocity,freemarker. 项目搭建专栏: https://blog.csdn.net/BADAO_LI ...

  3. 【SpringBoot】3、SpringBoot中整合Thymeleaf模板引擎

    SpringBoot 为我们提供了 Thymeleaf 自动化配置解决方案,所以我们在 SpringBoot 中使用 Thymeleaf 非常方便 一.简介 Thymeleaf是一个流行的模板引擎,该 ...

  4. springboot shiro ajax,SpringBoot Shiro 登录成功后返回json数据 shiro使用ajax登录

    老规矩,先上代码: protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletReques ...

  5. SpringBoot——整合数据库,springSecurity,shiro、整合thymeleaf

    一.springboot--JDBC 狂神说SpringBoot07:整合JDBC 1.引入web.JDBC API.mysql Driver <dependency><groupI ...

  6. Spring Boot 综合示例-整合thymeleaf、mybatis、shiro、logging、cache开发一个文章发布管理系统...

    一.概述 经过HelloWorld示例(Spring Boot 快速入门(上)HelloWorld示例)( Spring Boot  快速入门 详解 HelloWorld示例详解)两篇的学习和练习,相 ...

  7. Shiro与SpringBoot整合,实现登录拦截、用户认证、用户授权等。实战demo

    文章目录 开篇必读: 一.开发环境 二.项目搭建 三.配置 shiro 配置类 1.自定义 Realm 类. 2.创建shiro配置类. 四.创建页面.Controller. Service等. 五. ...

  8. Shiro 入门笔记,整合SpringBoot,Redis

    Shiro 入门笔记 视频地址:https://www.bilibili.com/video/BV1uz4y197Zm 感谢编程不良人的教程 1. 权限管理 权限管理包括用户 身份认证 和 授权 两部 ...

  9. Day374.shiro授权Shiro+jsp整合Springboot -Shiro

    Shiro授权 一.授权 授权,即访问控制,控制谁能访问哪些资源.主体进行身份认证后需要分配权限方可访问系统的资源,对于某些资源没有权限是无法访问的. 二.关键对象 授权可简单理解为who对what( ...

  10. Springboot -Shiro整合JWT(注解形式)

    Springboot -Shiro整合JWT(注解形式) 在这里只展示核心代码,具体的请访问github 参考timo 依赖导入 <dependencies><dependency& ...

最新文章

  1. 更改eclipse的Package Explorer的字体
  2. 无边框窗体的移动(winform/wpf)
  3. 中国在线英语培训行业投资热点分析与需求前景预测报告2022版
  4. JSON是什么?如何产生的?
  5. 升级浏览器_微软IE11浏览器 最后的升级机会
  6. 两本电子书 |Flink 最佳学习实践 | 从 0 到 1 学会 Apache Flink
  7. CentOS7下初始化PostgreSQL
  8. easyExcel 处理ExcelDataConvertException异常,获取异常的数据行列值等信息
  9. python中使用动量交易策略
  10. svn安装以及初步使用
  11. 计算机系毕业论文绪论,本科毕业论文绪论范文
  12. php超小免杀大马_php大马免杀技巧 | bypass waf
  13. 图文配置docker阿里云加速器教程
  14. 二进制和十进制的相互转换
  15. 获取当天零点/最晚时间戳
  16. android aar组件化,android module解耦组件化总体概述(推荐)
  17. Mysql查询当天,本周,本月所有数据记录
  18. 处理团队人际关系的九大原则
  19. 微信小程序vant 输入框问题
  20. Flutter的isolate异步线程机制及使用实战详解

热门文章

  1. 高薪、高收入程序员背后全是辛酸泪!熬夜,作息饮食不规律,体重增加,掉头发,黑眼圈,生病,鼠标手,颈椎病,免疫力下降?
  2. 自制模仿谷歌搜索UI的网页
  3. WPF 触摸屏小键盘样式
  4. A*算法最合理的数据结构
  5. python 绘制3D图
  6. directive-自定义指令
  7. 解决比较Oracle中CLOB字段问题--转自混世者的专栏
  8. java计算器自述文件_自述文件 - Unreal Engine
  9. JSR 168 翻译03
  10. 2021-05-11PLC通信Libnodave-明天继续