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";
    }
}
相关推荐
消失的旧时光-19431 分钟前
ScheduledExecutorService
android·java·开发语言
勇闯逆流河2 分钟前
【C++】用红黑树封装map与set
java·开发语言·数据结构·c++
码事漫谈13 分钟前
从外行到AI指挥官:你必须掌握的五大「程序员思维」
后端
Moonbit14 分钟前
MoonBit 开发者激励计划开启|赢取价值 $20 Copilot 月卡权益!
后端
码事漫谈16 分钟前
通信的三种基本模式:单工、半双工与全双工
后端
Q_Q51100828521 分钟前
python+uniapp基于微信小程序团购系统
spring boot·python·微信小程序·django·uni-app·node.js·php
前端中后台23 分钟前
如何防止短信验证码接口被盗刷
后端
SpiderPex23 分钟前
论MyBatis和JPA权威性
java·mybatis
小猪咪piggy40 分钟前
【微服务】(1) Spring Cloud 概述
java·spring cloud·微服务
lkbhua莱克瓦2442 分钟前
Java基础——面向对象进阶复习知识点8
java·笔记·github·学习方法