【笔记】springBoot快速 整合shiro-redis和thymeleaf

【学习,共享,扩展,笔记】springBoot快速集成Shiro和jsp_深渊码头-CSDN博客

你可以去看上一篇文章,这里的代码是基于上一篇文章进行代码调整

下面是新版笔记,修复了由于使用shiro-redis-spring-boot-starter导致shiro配置失效的问题

【笔记2】SpringBoot快速整合ShiroRedis与Thymeleaf(完整版)_深渊码头-CSDN博客

pom文件调整

把旧的pom文件调整为新的pom

旧的pom.xml

<!--shiro-boot war 项目使用这个maven坐标库 -->
<dependency>
	<groupId>org.apache.shiro</groupId>
	<artifactId>shiro-spring-boot-web-starter</artifactId>
	<version>1.8.0</version>
</dependency>
<!-- jsp页面使用jstl标签 -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>

<!-- 用于编译jsp -->
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
	<scope>provided</scope>
</dependency>

替换成为新的pom.xml 

<dependency>
	<groupId>org.</groupId>
	<artifactId>shiro-redis-spring-boot-starter</artifactId>
	<version>3.3.1</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

 官方文档,往下拉就可以找到crazycake 整合spring boot的文档

shiro-redis | shiro only provide the support of ehcache and concurrentHashMap. Here is an implement of redis cache can be used by shiro. Hope it will help you!shiro only provide the support of ehcache and concurrentHashMap. Here is an implement of redis cache can be used by shiro. Hope it will help you!http://alexxiyang.github.io/shiro-redis/ 

在application.properties新增配置

#--------------------shiro-redis配置------------------------
#redis地址
shiro-redis.redis-manager.host=127.0.0.1:6379
#redis密码
#shiro-redis.redis-manager.password=12345
#用户信息存入redis第几个库
shiro-redis.redis-manager.database=5
#实体类id,默认是id,找不到id则会报错
shiro-redis.cache-manager.principal-id-field-name=userId

#自定义redis关键字前缀的会话管理
shiro-redis.session-dao.key-prefix=token:user-session:
#自定义redis关键字前缀缓存管理
shiro-redis.cache-manager.key-prefix=token:authorization:

#--------------------shiro-redis配置------------------------

特别说明

shiro-redis.cache-manager.principal-id-field-name

这个属性需要配置一个id,如果你的实体类默认是有id这个属性是可以不用配置,默认是获取getId的,也可以指定其他字段

只需要把jsp页面修改为html,移除jsp头部信息,并且把页面发到resources/templates目录下

403.jsp页面代码修改如下面:

403.html

<html xmlns:th="http://www.thymeleaf.org">
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>你无权限操作~~~</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width" />
<link
	href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,300,400italic,400,600italic,600,700italic,700,800italic,800"
	rel="stylesheet" type="text/css" />
<link
	href="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
	rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="box col-md-6 col-md-offset-3">
				<div class="custom-header">
					<img
						src="http://shiro.apache.org/assets/images/apache-shiro-logo.png" />
				</div>
				<div class="logo">
					<h1 th:text="${code}"> 403 </h1>
				</div>
				<p class="lead text-muted">你的权限不足,充值一个998吧</p>
				<a href="/" class="btn btn-primary">Go Home</a>
			</div>
		</div>
	</div>
</body>
</html>

到此,springBoot整合shiro-redis基本完成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值