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 分钟前
SpringBoot 控制器的动态注册与卸载
java·spring boot·后端
前端付豪26 分钟前
17、自动化才是正义:用 Python 接管你的日常琐事
后端·python
我是一只代码狗30 分钟前
springboot中使用线程池
java·spring boot·后端
hello早上好43 分钟前
JDK 代理原理
java·spring boot·spring
PanZonghui1 小时前
Centos项目部署之安装数据库MySQL8
linux·后端·mysql
PanZonghui1 小时前
Centos项目部署之运行SpringBoot打包后的jar文件
linux·spring boot
PanZonghui1 小时前
Centos项目部署之Java安装与配置
java·linux
Victor3561 小时前
MySQL(119)如何加密存储敏感数据?
后端
用户3966144687191 小时前
TypeScript 系统入门到项目实战-慕课网
后端