需求缘起:
在shiro和jsp配合使用的时候,有针对jsp的shiro标签,当我们使用的是thymeleaf也是可以使用shiro标签的,这就是本节要解决的问题。
本节大纲:
(1)添加依赖
(2)在ShiroConfiguration添加配置
(3)在index方法中存放userInfo
(4)调整index.html
(2)在ShiroConfiguration添加配置
(3)在index方法中存放userInfo
(4)调整index.html
接下来看下具体的内容:
(1)添加依赖
<dependency> <groupId>com.github.theborakompanioni</groupId> <artifactId>thymeleaf-extras-shiro</artifactId> <version>1.0.2</version> </dependency>
(2)在ShiroConfiguration添加配置
@Bean public ShiroDialect shiroDialect() { return new ShiroDialect(); }
(3)在index方法中存放userInfo对象
修改HomeController的index方法:
@RequestMapping(value={"/","/index"}) public String index(Map<String,Object> map){ System.out.println("HomeController.index()"); //获取到用户信息; Subject subject = SecurityUtils.getSubject(); UserInfo ui = (UserInfo) subject.getPrincipal(); map.put("userInfo",ui); return "/index"; }
(4)调整index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Insert title here</title> </head> <body> <h3>主界面--<span th:text="'登录账号:'+${userInfo.username}+'--名称:'+${userInfo.name}">user</span></h3> <a href="/logout">退出</a> <hr /> <!-- 这些实际从数据库中进行查询,可以在 --> <h5>这是通过shiro标签的方式;</h5> <p shiro:hasRole="admin"> <a>管理员角色</a> </p> <p shiro:hasPermission="userInfo:query"> <a href="/userInfo/userList">用户查询</a> </p> <p shiro:hasPermission="userInfo:add"> <a href="/userInfo/userAdd">用户添加</a> </p> <hr /> <h5>从数据库加载菜单</h5> <div th:each="roleList:${userInfo.roleList}"> <span th:text="${roleList.description}"></span> <!-- 角色下所有的所有菜单,实际开发中,只需要获取所有的权限就可以了,无所谓是哪个角色的; --> <p style="color:blue;margin-left:30px;" th:each="permission:${roleList.permissions}"> <a th:href="${permission.url}" th:text="${permission.name}"></a> </p> </div> </body> </html>
à悟空学院:https://t.cn/Rg3fKJD
学院中有Spring Boot相关的课程!点击「阅读原文」进行查看!
SpringBoot视频:http://t.cn/A6ZagYTi
Spring Cloud视频:http://t.cn/A6ZagxSR
SpringBoot Shiro视频:http://t.cn/A6Zag7IV
SpringBoot交流平台:https://t.cn/R3QDhU0
SpringData和JPA视频:http://t.cn/A6Zad1OH
SpringSecurity5.0视频:http://t.cn/A6ZadMBe
Sharding-JDBC分库分表实战:http://t.cn/A6ZarrqS
分布式事务解决方案「手写代码」:http://t.cn/A6ZaBnIr
相关推荐
功能描述: 用于在页面模板中应用Shiro框架提供的功能,例如权限验证、角色... 框架依赖:Spring/Spring Boot、Thymeleaf、Shiro 也可以在github上获取最新源码:https://github.com/edenyin307/thymeleaf-shiro-extags
springboot+thymeleaf+shiro标签1
基于SpringBoot2.0 + Spring Data Jpa + Thymeleaf + Shiro 开发的后台管理系统,采用分模块的方式便于开发和维护,支持前后台模块分别部署,目前支持的功能有:权限管理、部门管理、字典管理、日志记录、文件上传、...
使用官方推荐的thymeleaf做为模板引擎,shiro作为安全框架,主流技术,“一网打尽” 基于注解的sql写法,零XML,极简配置,一键前后台代码生成功能简介 1. 用户管理 2. 角色管理 3. 部门管理 4. 菜单管理 5. 系统...
spring boot+redis+shiro+mybatis+thymeleaf整合框架,引入了缓存,可以使整个项目能快速访问资源,并且提供shiro安全框架保证了资源的安全性。spring boot,mybatis则是现在开发的最新框架技术。并且引入了...
spring boot+mybatis+thymeleaf+apache shiro开发面向学习型的后台管理系统BootDo,参考地址 http://blog.csdn.net/zhaokejin521/article/details/78719722
该毕业设计使用了当前较为流行的spring boot,spring,spring mvc,mybatis,shiro框架分页处理使用了pagehelper进行操作 前台使用了模板语言thymeleaf,界面较为炫酷,适合年轻朋友。 开发工具采用的是IDEA。 该...
spring-boot-shiro:springboot 整合shiro rbac示例 spring-boot-file-upload:使用Spring Boot 上传文件示例 spring-boot-fastDFS:Spring Boot 整合FastDFS示例 spring-boot-actuator:Spring Boot Actuator 使用...
使用了当前较为流行的spring boot,spring,spring mvc,mybatis,shiro框架分页处理使用了pagehelper进行操作,前台使用了模板语言thymeleaf,界面较为炫酷,适合年轻朋友。开发工具采用的是IDEA。
Spring boot使用的各种示例,以最简单、最实用为标准 spring-boot-helloWorld:spring-boot的helloWorld版本 spring-boot-mybaits-annotation:注解版本 spring-boot-mybaits-xml:xml配置版本 spring-boot-...
本系统(基于SpringBoot+MyBatis+Apache Shiro+Bootstrap+Thymeleaf) 可用于开发所有企业级WEB应用系统(如:各种后台管理系统、CRM、ERP、CMS、OA、博客、论坛等...)。响应式布局,支持大部分浏览器(如:IE9+...
Spring Boot+Mybatis Plus+Thymeleaf实现用户登录和校验用户名是否重复功能
Spring Boot Thymeleaf中使用Shiro标签 Spring Boot Shiro在线会话管理 Spring Boot Shiro整合JWT 三、Spring Boot & Security教程 Spring Boot中开启Spring Security Spring Security自定义用户认证 Spring ...
整合mybatis-spring-boot-2.0-shiro-thymeleaf 简短的小demo,适合初学者
SpringBoot+Mybatis+Thymeleaf整合Shiro入门
基于Spring Boot+Apache Shiro+Thymeleaf+MyBatis开发的网站后台权限管理系统源码
注册用户可以修改个人信息和宠物信息,发布预约单(预约医生和美容师),在医院的商城购物,收藏商品,给官方留言,查看与自己相关的记录信息,如:病例记录、预约记录、问诊记录、订单记录等,注销退出系统。...
1.6 Spring Boot使用别的json解析框架 1.7 全局异常捕捉 1.8 Spring Boot datasource - mysql 1.9 JPA - Hibernate 1.10 使用JPA保存数据 1.11 使用JdbcTemplate 1.12 Spring Boot修改端口号 1.13 Spring Boot配置...
在基于Spring Boot、Spring Cloud 分布微服务开发过程中,根据实际项目环境,需要选择、集成符合项目需求的各种组件和积累各种解决方案。基于这样的背景下,我开源了本示例项目,方便大家快速上手Spring Boot、...