# resp1 **Repository Path**: CXGD/resp1 ## Basic Information - **Project Name**: resp1 - **Description**: 不好意思代码美开源仙子啊开一下给你们 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-07-11 - **Last Updated**: 2022-07-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 官网学习springboot >今天的视频,应该差不多可以夸个海口,全网独一份,没有雷同款! > >周三下午这边机房要打扫卫生,专门打扫,各自物品需要带走!!! > >原来的椅子需要归还,请三个班长各自班级再通知一下!!! > >spring[官方源码地址](https://github.com/spring-projects) > >mybatis[官方源码地址](https://github.com/mybatis) > >1. springboot-mybaits[源码](https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-samples/mybatis-spring-boot-sample-web) > >redis[官方源码地址](https://github.com/redis) > >mybatisPlus[官方源码](https://github.com/baomidou/mybatis-plus-samples/tree/master/mybatis-plus-sample-crud) > >Alibaba[官方源码](https://github.com/alibaba/spring-cloud-alibaba/tree/2.2.x/spring-cloud-alibaba-examples) > >apache[官网源码](https://github.com/apache/echarts) > >Springboot项目学习三步走: > >1. 为什么?(学习任何技术,先检索一下,该技术存在的目的) >2. 是什么?(百度一下,该技术如何解决相关问题的) >3. 怎么办?(查看官方demo,找到源码,根据如下动作搭建) > >Springboot项目搭4.5五步走: > >1. 部门软件需要提前安装基本环境; >2. 新建项目,选择项目对应包依赖(新手,看源码照抄;老手,只加必要的) >3. 修改配置文件(根据源码照抄); >4. 新增配置类(根据源码照抄) >5. 开始使用(根据源码照抄); 记住,除了基础,多数框架都是人为基于底层技术实现的,多数时候这些配置也仅仅是人家定义的规范,所谓规范就是我们用就好了,没有太多为什么 各个版本代码隐藏地址: [SpringBoot2.0.x](https://github.com/spring-projects/spring-boot/tree/2.0.x/spring-boot-samples) [SpringBoot2.1.x](https://github.com/spring-projects/spring-boot/tree/2.1.x/spring-boot-samples) 下载指定分支的代码命令 ```cmd git clone -b 2.1.x https://github.com/spring-projects/spring-boot ``` 一些大牛整合的springboot源码 1. [源码](https://gitee.com/goktech/spring-boot-demo) 2. [源码](https://gitee.com/ityouknow/spring-boot-examples) # 20220728 redis学习 ### 是什么 Redis(Remote Dictionary Server ),即**远程字典**服务,是一个开源的使用ANSI C语言编写、支持网络、**可基于内存亦可持久化**的日志型、**Key-Value数据库**,并提供多种语言的API。 关系型数据库:MySQL 1. 预先定义数据结构 2. 数据存在关联关系 非关系型数据库(NoSQL) #待补充定义 **redis** 1. Map 其中String即cacheName;Object即常用数据类型; 2. 16个库 3. 槽 ### 为什么 通过redis是一种NoSQL数据库,可以快速的完成数据的写入和读取功能 读取性能非常高 ### 怎么办 1、下载redis软件包 > redis 1. 启动redis ```cmd redis-server.exe redis.windows.conf ``` ``` redis-cli.exe -h 127.0.0.1 -p 6379 ``` 2. 学习redis基础的命令&数据类型 https://www.processon.com/view/link/62d0c476e0b34d0bd4c60da0#map 3. 添加pom的redis依赖 ```xml org.springframework.boot spring-boot-starter-data-redis-reactive ``` 4. 创建一个配置类 ```JAVA package cn.edu.qzit.linpq.config; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; import java.io.Serializable; import java.net.UnknownHostException; /** * Desc : TODO * ClassName : cn.edu.qzit.linpq.config.RedisConfig * * @author : 林鹏群 * @date : 2022/7/28 9:25 */ @Configuration @EnableCaching @AutoConfigureAfter(RedisAutoConfiguration.class) public class RedisConfig { @Bean public RedisTemplate redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) throws UnknownHostException { RedisTemplate template = new RedisTemplate<>(); template.setKeySerializer(RedisSerializer.string()); template.setValueSerializer(RedisSerializer.json()); template.setConnectionFactory(lettuceConnectionFactory); return template; } } ``` 5. 给原有的查询添加注解 ```java @Cacheable(value = "user",key = "#id") public Student get(Integer id){ Student student = studentMapper.findById(id); log.info("[查询学生信息Service]:{}",student); return student; } /** * CachePut注解需要跟Cacheable注解的方法拥有相同的返回值,否则失效 * @param student * @return */ @CachePut(value = "user",key = "#student.id") public Student saveCache(Student student){ Student save = studentRepository.save(student); log.info("[保存学生信息Service]:{}",student); return save; } @CacheEvict(value = "user",key = "#id") public void deleteCache(String id){ studentRepository.deleteById(id); log.info("[删除学生信息Service]:{}",id); } ``` redis对对象的缓存数据结构类似 Map>> Map<"cacheName",List>> > 如果是自己电脑,安装Utools,再按下alt + 空格 > > 机房电脑 按下 alt + 空格 > > 调用出utools工具,点击工具右边图标 > > ![image-20220728112600213](README.assets/image-20220728112600213.png) > > 安装插件 medis > > ![image-20220728112855757](README.assets/image-20220728112855757.png) 上午内容总结: 三个 注解: ``` //cacheable注解一般用于查询方法上使用,该注解的特点是,当redis中key不存在的时候,有且仅有运行一次。一旦该注解深生效后,被注解的方法体不再执行。 //其中value属性代表cacheName,key代表缓存的key @Cacheable(value = "user", key = "#id") //cachePut注解一般用于新增或者修改的方法上面,该注解的特点是每次运行都会生效,确保redis缓存中的数据是最新的。 //cachePut注解的方法不能是void类型,否则缓存为空,必须跟cacheable拥有相同的返回类型。 @CachePut(value = "user", key = "#student.id") //cacheEvict注解一般用于删除方法上面,该注解是用来根据缓存的名字以及key删除对应的缓存信息。 //如果cachename的key被删除后,cacheable会再次被允许执行 @cacheEvict(value = "user", key = "#id") ``` > 名词解释: > > 数据库:类似mysql的数据库,不同的是redis用有16个相互隔离的数据库,默认使用0号数据库 > > 槽:可以理解为一个redis的数据库中,有16384个仓库,这些仓库拥有编号,在我们存放数据的时候,redis会用数据的key去计算对应匹配的仓库,这样为更快的检索数据。 一个redis的服务启动后,默认有16个**数据库**:我们一个系统默认一次仅用一个库 一个数据库拥有16384个**槽** > 20220728 > > 作业1:升级自己原有的系统,加入redis缓存。尝试缓存一个复杂数据类型。例如:Student类里面有一个List > > 作业2:https://gitee.com/goktech/spring-boot-demo/tree/master/demo-codegen clone该代码,尝试允许代码生成器,要求添加一个自定义的模板 > > 作业3:根据 https://www.processon.com/view/link/62d0c476e0b34d0bd4c60da0#map 将redis的常见命令,手动敲写一遍;