SpringBoot2.7.14整合redis7

需要的依赖库:

XML 复制代码
<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

单节点整合SpringBoot:

html 复制代码
spring:
  redis:
    database: 0
    host: 192.168.56.201
    port: 6379
    username: xxxxxx
    password: XXXXXXXXX

Student.java:

java 复制代码
package com.lscbaiotaigc.entiies;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student implements Serializable {

    private String id;
    private String name;
    private int age;
    private Date birthday;
}

StudentController.java:

java 复制代码
package com.lscbaiotaigc.controller;


import com.lscbaiotaigc.entities.Student;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class StudentController {

    @Resource
    private RedisTemplate redisTemplate;

    @PostMapping("/setStudent")
    public String setStudent(@RequestBody Student student){
        redisTemplate.opsForValue().set("student1", student);
        return "SUCCESS";
    }
}
相关推荐
架构师沉默2 分钟前
为什么一个视频能让全国人民同时秒开?
java·后端·架构
生命不息战斗不止(王子晗)10 分钟前
mysql基础语法面试题
java·数据库·mysql
umeelove3513 分钟前
Java进阶(ElasticSearch的安装与使用)
java·elasticsearch·jenkins
redaijufeng16 分钟前
Node.js(v16.13.2版本)安装及环境配置教程
java
齐齐大魔王30 分钟前
linux-线程编程
java·linux·服务器
掘金码甲哥35 分钟前
同样都是九年义务教育,他知道的AI算力科普好像比我多耶
后端
sthnyph43 分钟前
SpringBoot Test详解
spring boot·后端·log4j
我真会写代码1 小时前
Redis核心特性详解:事务、发布订阅与数据删除淘汰策略
java·数据库·redis
饼干哥哥1 小时前
搭建一个云端Skills系统,随时随地记录TikTok爆款
前端·后端
IT 行者1 小时前
LangChain4j 集成 Redis 向量存储:我踩过的坑和选型建议
java·人工智能·redis·后端