添加依赖
<!--springboot整合redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--http页面爬取整合识别-->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<!-- spring session的依赖,开启自动添加 -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
spring:
##设置redis中间缓冲
redis:
host: 192.168.10.130
port: 6379
password: 123456
允许自动将session和cookie加载至redis
package com.example.springbootmybatis.configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
/**
* @author nongChaTea
* @date 2021/10/1 11:10
*/
@EnableRedisHttpSession()
public class RedisConfig {
}
需要注意的是,序列化添加
在需要添加redis的pojo/bean上实现implements Serializable
/**
* @author nongChaTea
*/
@Data
public class User implements Serializable {
private long id;
@NonNull
private String uuid;
@NonNull
private String username;
@NonNull
private String password;
private String gender;
private String accountName;
private String birthday;
private String address;
private String selfIntroduction;
private String email;
private String createTime;
private String lastChangeTime;
public User(long id, String uuid, String username, String password, String gender, String accountName, String birthday, String address, String selfIntroduction, String email, String createTime, String lastChangeTime) {
this.id = id;
this.uuid = uuid;
this.username = username;
this.password = password;
this.gender = gender;
this.accountName = accountName;
this.birthday = birthday;
this.address = address;
this.selfIntroduction = selfIntroduction;
this.email = email;
this.createTime = createTime;
this.lastChangeTime = lastChangeTime;
}
public User() {
}
}