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";
    }
}
相关推荐
小灰灰搞电子3 小时前
Rust+Slint 实现动态消息提示框源码分享
开发语言·后端·rust
魏 无羡4 小时前
webclient
java·webclient
小奏技术4 小时前
10 MB 的 Postman 替代品,启动不到 1 秒
后端
东风破_4 小时前
Text2SQL :用自然语言操作 SQLite 数据库
人工智能·后端
神仙别闹4 小时前
基于 C++ 实现两个有序链表序列的交集
java·c++·链表
swordbob5 小时前
ReentrantLock 与 AQS 完整学习手册
java·开发语言
m0_587383006 小时前
全民健身解决方案软件开发实战:从架构设计到落地指南
java·spring boot·spring·架构·需求分析
白山编程大哥6 小时前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
一技安身7 小时前
【信创】Docker‑Compose V2 两种离线部署(独立模式、插件模式)简易教程
java·docker·eureka
七夜zippoe7 小时前
为什么 2026 年每个 Java 团队都该懂 AI Agent
java·开发语言·人工智能