小程序微信公众平台,外贸网站设计制作优化推广,福田做网站哪家专业,wordpress 知识 管理系统文章目录 1、创建项目#xff0c;添加Redis依赖2、创建实体类Student3、创建Controller4、配置application.yml5、整合完成 Redis (
Remote Dictionary Server #xff09;是一个开源的内存数据库#xff0c;遵守 BSD 协议#xff0c;它提供了一个高性能的键值#xff08… 文章目录 1、创建项目添加Redis依赖2、创建实体类Student3、创建Controller4、配置application.yml5、整合完成 Redis (
Remote Dictionary Server 是一个开源的内存数据库遵守 BSD 协议它提供了一个高性能的键值
key - value 存储系统常用于缓存、消息队列、会话存储等应用场景。 SpringBoot整合
Redis流程如下 1、创建项目添加Redis依赖
创建Springboot项目添加Redis依赖 添加依赖后pom.xml内容如下
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.3.3/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom/groupIdartifactIdredis/artifactIdversion0.0.1-SNAPSHOT/versionnameredis/namedescriptionredis/descriptionurl/licenseslicense//licensesdevelopersdeveloper//developersscmconnection/developerConnection/tag/url//scmpropertiesjava.version22/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- redis --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency!-- 连接池 --dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-pool2/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/project2、创建实体类Student
创建包com.redis.entity创建实体类Student
package com.redis.entity;import lombok.Data;import java.io.Serializable;
import java.util.Date;Data
public class Student implements Serializable {private Long id;private String name;private Double score;private Date birthday;
}3、创建Controller
创建包com.redis.controller创建类StudentController
package com.redis.controller;import com.redis.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;RestController
public class StudentController {Autowiredprivate RedisTemplate redisTemplate;PostMapping(/set)public void set(RequestBody Student student){redisTemplate.opsForValue().set(stu,student);}GetMapping(/get/{key})public Student get(PathVariable(key) String key){return (Student) redisTemplate.opsForValue().get(key);}DeleteMapping(/delete/{key})public boolean delete(PathVariable(key) String key){redisTemplate.delete(key);return redisTemplate.hasKey(key);}
}4、配置application.yml
application.yml内容如下
spring:data:redis:database: 0host: localhostport: 63795、整合完成
整合完成快来试试吧。