添加依赖

    1. <!--springboot整合redis-->
    2. <dependency>
    3. <groupId>org.springframework.boot</groupId>
    4. <artifactId>spring-boot-starter-data-redis</artifactId>
    5. </dependency>
    6. <!--http页面爬取整合识别-->
    7. <dependency>
    8. <groupId>org.jsoup</groupId>
    9. <artifactId>jsoup</artifactId>
    10. <version>1.10.2</version>
    11. </dependency>
    12. <!-- spring session的依赖,开启自动添加 -->
    13. <dependency>
    14. <groupId>org.springframework.session</groupId>
    15. <artifactId>spring-session-data-redis</artifactId>
    16. </dependency>
    1. spring:
    2. ##设置redis中间缓冲
    3. redis:
    4. host: 192.168.10.130
    5. port: 6379
    6. password: 123456

    允许自动将session和cookie加载至redis

    1. package com.example.springbootmybatis.configuration;
    2. import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
    3. /**
    4. * @author nongChaTea
    5. * @date 2021/10/1 11:10
    6. */
    7. @EnableRedisHttpSession()
    8. public class RedisConfig {
    9. }

    需要注意的是,序列化添加
    在需要添加redis的pojo/bean上实现implements Serializable

    1. /**
    2. * @author nongChaTea
    3. */
    4. @Data
    5. public class User implements Serializable {
    6. private long id;
    7. @NonNull
    8. private String uuid;
    9. @NonNull
    10. private String username;
    11. @NonNull
    12. private String password;
    13. private String gender;
    14. private String accountName;
    15. private String birthday;
    16. private String address;
    17. private String selfIntroduction;
    18. private String email;
    19. private String createTime;
    20. private String lastChangeTime;
    21. 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) {
    22. this.id = id;
    23. this.uuid = uuid;
    24. this.username = username;
    25. this.password = password;
    26. this.gender = gender;
    27. this.accountName = accountName;
    28. this.birthday = birthday;
    29. this.address = address;
    30. this.selfIntroduction = selfIntroduction;
    31. this.email = email;
    32. this.createTime = createTime;
    33. this.lastChangeTime = lastChangeTime;
    34. }
    35. public User() {
    36. }
    37. }