学校网站建站,公司公司网站建设公司,电商网站与大数据,红酒营销型网站建设基于SpringBoot的外卖项目的优化1、缓存优化1.1、缓存短信验证码问题分析代码改造1.2、缓存菜品数据实现思路1.3、Spring Cache介绍常用注解CachePutCacheEvictCacheable使用方式1.4、缓存套餐数据实现思路代码改造2、读写分离2.1、主从复制存在的问题介绍配置配置主库--master…
基于SpringBoot的外卖项目的优化1、缓存优化1.1、缓存短信验证码问题分析代码改造1.2、缓存菜品数据实现思路1.3、Spring Cache介绍常用注解CachePutCacheEvictCacheable使用方式1.4、缓存套餐数据实现思路代码改造2、读写分离2.1、主从复制存在的问题介绍配置配置主库--master配置从库--slave2.2、读写分离背景Sharding-JDBC介绍案例2.3、项目中实现读写分离数据库环境准备3、Nginx3.1、概述介绍下载和安装目录结构3.2、命令3.3、配置文件的结构3.4、具体应用部署静态资源反向代理介绍配置负载均衡介绍配置负载均衡策略4、前后端分离问题4.1、前后端分离开发介绍开发流程前端技术栈4.2、YApi/FastApi/Apifox介绍使用4.3、Swagger介绍使用常用注解4.4、项目部署部署架构部署环境说明申明 未经许可禁止以任何形式转载若要引用请标注链接地址。 全文共计3077字阅读大概需要3分钟 更多学习内容 欢迎关注我的个人公众号不懂开发的程序猿 友情链接 基于SpringBoot的外卖项目(详细开发过程)
1、缓存优化
1.1、缓存短信验证码
问题分析 代码改造
pom.xml
!--开启 redis 缓存--
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId
/dependencyapplication.yml 1.2、缓存菜品数据
实现思路 把所有的菜品数据缓存到redis中 如果菜品数据发生了更新和添加操作就需要清理下redis缓存 1.3、Spring Cache
介绍 常用注解 默认的缓存技术底层是基于map来缓存数据因此服务停止后缓存数据就消失了
但是如果采用RedisCache作为缓存就不会存在这个问题
CachePut CacheEvict Cacheable 使用方式 1.4、缓存套餐数据
实现思路 代码改造
pom.xml
!--开启 cache 缓存--
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId
/dependencyapplication.yml 在启动类上开启缓存注解EnableCaching 在SetmealController的list方法上加入Cacheable注解: 通用返回类R需要实现Serializable序列化接口 用Redis图形化桌面工具也可以看到缓存中有套餐数据 新增套餐和删除套餐也类似都需要加入CacheEvict注解 2、读写分离
2.1、主从复制
存在的问题 介绍 配置 配置主库–master 配置从库–slave 2.2、读写分离
背景 Sharding-JDBC介绍 案例 pom
dependencygroupIdorg.apache.shardingsphere/groupIdartifactIdsharding-jdbc-spring-boot-starter/artifactIdversion4.0.0-RC1/version
/dependency配置数据源
server:port: 8080
mybatis-plus:configuration:#在映射实体或者属性时将数据库中表名和字段名中的下划线去掉按照驼峰命名法映射map-underscore-to-camel-case: truelog-impl: org.apache.ibatis.logging.stdout.StdOutImplglobal-config:db-config:id-type: ASSIGN_ID
spring:shardingsphere:datasource:names:master,slave# 主数据源master:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.138.100:3306/rw?characterEncodingutf-8username: rootpassword: root# 从数据源slave:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.138.101:3306/rw?characterEncodingutf-8username: rootpassword: rootmasterslave:# 读写分离配置load-balance-algorithm-type: round_robin #轮询# 最终的数据源名称name: dataSource# 主库数据源名称master-data-source-name: master# 从库数据源名称列表多个逗号分隔slave-data-source-names: slaveprops:sql:show: true #开启SQL显示默认falsemain:allow-bean-definition-overriding: true2.3、项目中实现读写分离
数据库环境准备 跟上面的案例一样准备好主从两个数据库、导pom、修改配置文件
3、Nginx
3.1、概述
介绍 下载和安装 目录结构 3.2、命令
查看版本
cd /usr/local/nginx/sbin
./nginx -v检查配置文件的正确性
cd /usr/local/nginx/sbin
./nginx -t启动和停止
简单启动
cd /usr/local/nginx/sbin
./nginx复杂启动
cd /usr/local/nginx/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf查看进程
ps -ef | grep nginx停止
cd /usr/local/nginx/sbin
./nginx -s quit或
cd /usr/local/nginx/sbin
./nginx -s stop重新加载配置文件
cd /usr/local/nginx/sbin
./nginx -s reload
systemctl status nginx3.3、配置文件的结构 3.4、具体应用
部署静态资源 反向代理
介绍 配置 负载均衡
介绍 配置 负载均衡策略 4、前后端分离
问题
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NvB6CWsL-1677236950620)(E:/typora/image-20230224124113816.png)]
4.1、前后端分离开发
介绍 开发流程 前端技术栈 4.2、YApi/FastApi/Apifox
介绍 使用
4.3、Swagger
介绍 使用 pom dependencygroupIdcom.github.xiaoymin/groupIdartifactIdknife4j-spring-boot-starter/artifactIdversion3.0.2/version/dependencyBeanpublic Docket createRestApi() {// 文档类型return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(com.itheima.reggie.controller)).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title(瑞吉外卖).version(1.0).description(瑞吉外卖接口文档).build();}WebMvcConfig LoginCheckFilter 启动项目
进入网址www.localhost:8080/doc.html 就会生成对应的接口文档 常用注解 将这些注解加在对应的类上属性上生成的doc文档就含有中文解释 4.4、项目部署
部署架构 部署环境说明 –end–