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";
    }
}
相关推荐
m0_639906945 分钟前
Linux 操作系统入门:目录结构、服务排查常用命令、Shell 脚本基础
linux·运维·后端
2501_944521597 分钟前
Deepmerge 跨端三方库仓颉适配全流程
java·python·eclipse·github
holly就是我1 小时前
AI 编程助手为什么跑偏?用开源 ccglass 看清 Prompt、工具调用和 Token 消耗
人工智能·后端
鸿蒙开发1 小时前
共享 Schema 与 SchemaFactory
前端·后端·harmonyos
用户788477316341 小时前
小程序后端三选一:云开发、.NET WebAPI、Node,我按客户现状分了三种答案
后端
aiopencode1 小时前
局域网设备抓包怎么做?用 TraceEagle 抓电视、游戏机和 IoT 流量
后端·ios
智驭未来掌门人1 小时前
CLion 开发 Qt 项目的优势
后端
EnCi Zheng1 小时前
后端怎么把AI接口稳定安全低成本接进业务:超时重试、密钥隔离与成本熔断清单
人工智能·后端·安全·架构·api
Bazingga1 小时前
从一家酒店讲懂Docker
后端
南归北隐1 小时前
Spring AI Alibaba Graph框架实现MCP数据库查询实战
java·后端·spring ai·mcp·spring ai mcp