当前位置: 首页 > news >正文

苍穹外卖day07——缓存菜品套餐+购物车功能实现

缓存菜品——需求设计与分析

问题说明

用户访问量过大带来的一个直接效果就是响应速度慢,使用体验下降。

 实现思路

使用redis缓存菜品数据,减少数据库查询操作。

 页面展示上基本就是同一个分类在同一页,所以key-value结构可以使用不同的分类来做key。

缓存菜品——代码开发

在小程序每一次点击不同的分类,后端哪里都会刷刷刷的连接数据库查询返回,对后端压力肥肠的大,因此使用Redis的作用在这里就能体现了。

修改用户端的DishController代码

@RestController("userDishController")
@RequestMapping("/user/dish")
@Slf4j
@Api(tags = "C端-菜品浏览接口")
public class DishController {@Autowiredprivate DishService dishService;@Autowiredprivate RedisTemplate redisTemplate;/*** 根据分类id查询菜品** @param categoryId* @return*/@GetMapping("/list")@ApiOperation("根据分类id查询菜品")public Result<List<DishVO>> list(Long categoryId) {//构造redis中的key,规则:dish_分类idString key="dish_"+categoryId;//查询redis中是否存在菜品数据,放进去的是什么类型的对象,取出来就要是什么类型的东西。List<DishVO>  list= (List<DishVO>) redisTemplate.opsForValue().get(key);if(list!=null&&list.size()>0){//如果存在,直接返回,无需查询数据库return Result.success(list);}Dish dish = new Dish();dish.setCategoryId(categoryId);dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品//如果不存在,查询数据库,将查询到的数据放入redis中list = dishService.listWithFlavor(dish);redisTemplate.opsForValue().set(key,list);return Result.success(list);}
}

相对应的在redis里面会有缓存数据

修改管理端的DIshController代码 

要保证数据一致性,数据库数据发生改变时要及时修改redis,不然小程序端的数据和数据库数据会不一致。

/*** 菜品管理*/
@RestController
@RequestMapping("/admin/dish")
@Api(tags="菜品相关接口")
@Slf4j
public class DishController {@Autowiredprivate DishService dishService;@Autowiredprivate RedisTemplate redisTemplate;/*** 新增菜品* @param dishDTO* @return*/@PostMapping@ApiOperation("新增菜品")public Result save(@RequestBody DishDTO dishDTO){log.info("新增菜品:{}",dishDTO);dishService.saveWithFlavor(dishDTO);//清理缓存数据String key="dish_"+dishDTO.getCategoryId();cleanCache(key);return Result.success();}/*** 菜品分页查询* @param dishPageQueryDTO* @return*/@GetMapping("/page")@ApiOperation("菜品分页查询")public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){log.info("菜品分页查询:{}",dishPageQueryDTO);PageResult pageResult= dishService.pageQuery(dishPageQueryDTO);return Result.success(pageResult);}/*** 菜品批量删除* 通过@RequestParam注解将字符串转换为数组* @param ids* @return*/@DeleteMapping@ApiOperation("菜品批量删除")public Result delete(@RequestParam List<Long> ids){log.info("菜品批量删除:{}",ids);dishService.deleteBatch(ids);//将所有的菜品缓存数据清理掉,所有以dish_开头的keycleanCache("dish_*");return Result.success();}/*** 根据id查询菜品* @param id* @return*/@GetMapping("/{id}")@ApiOperation("根据id查询菜品")public Result<DishVO> getById(@PathVariable Long id){log.info("根据id查询菜品:{}",id);DishVO dishVO=dishService.getByIdWithFlavor(id);return Result.success(dishVO);}/*** 根据id修改菜品基本信息和对应口味信息* @param dishDTO* @return*/@PutMapping@ApiOperation("修改菜品")public Result update(@RequestBody DishDTO dishDTO){log.info("修改菜品:{}",dishDTO);dishService.updateWithFlavor(dishDTO);//将所有的菜品缓存数据清理掉,所有以dish_开头的keycleanCache("dish_*");return Result.success();}/*** 根据分类id查询菜品* @param categoryId* @return*/@GetMapping("list")@ApiOperation("根据分类id查询菜品")public Result<List<Dish>> list(Long categoryId){List<Dish> list=dishService.list(categoryId);return Result.success(list);}/*** 菜品起售停售* @param status* @param id* @return*/@PostMapping("/status/{status}")@ApiOperation("菜品起售停售")public Result<String> startOrStop(@PathVariable Integer status, Long id){dishService.startOrStop(status,id);//将所有的菜品缓存数据清理掉,所有以dish_开头的keycleanCache("dish_*");return Result.success();}/*** 清理缓存数据* @param pattern*/private void cleanCache(String pattern){Set keys = redisTemplate.keys(pattern);redisTemplate.delete(keys);}
}

缓存菜品——功能测试

不做了,好累啊。

缓存套餐——Spring Cache

在以下这个文章里面。Spring Cache_北岭山脚鼠鼠的博客-CSDN博客

实现思路+代码开发

 在启动类上加入注解

@EnableCaching //开启缓存注解的功能

 user端

    /*** 条件查询** @param categoryId* @return*/@GetMapping("/list")@ApiOperation("根据分类id查询套餐")@Cacheable(cacheNames = "sermealCache",key="#categoryId")public Result<List<Setmeal>> list(Long categoryId) {Setmeal setmeal = new Setmeal();setmeal.setCategoryId(categoryId);setmeal.setStatus(StatusConstant.ENABLE);List<Setmeal> list = setmealService.list(setmeal);return Result.success(list);}

admin端

/*** 套餐管理*/
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags="套餐相关接口")
@Slf4j
public class SetmealController {@Autowiredprivate SetmealService setmealService;/*** 新增套餐* @param setmealDTO* @return*/@PostMapping@ApiOperation("新增套餐")@CacheEvict(cacheNames = "setmealCachce",key="#setmealDTO.categoryId")public Result save(@RequestBody SetmealDTO setmealDTO){setmealService.saveWithDish(setmealDTO);return Result.success();}/*** 分页查询* @param setmealPageQueryDTO* @return*/@GetMapping("/page")@ApiOperation("分页查询")public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);return Result.success(pageResult);}/*** 批量删除套餐* @param ids* @return*/@DeleteMapping@ApiOperation("批量删除套餐")@CacheEvict(cacheNames = "setmealCache",allEntries = true)public Result delete(@RequestParam List<Long> ids){setmealService.deleteBatch(ids);return Result.success();}/*** 根据id查询套餐,用于修改页面回显数据** @param id* @return*/@GetMapping("/{id}")@ApiOperation("根据id查询套餐")public Result<SetmealVO> getById(@PathVariable Long id) {SetmealVO setmealVO = setmealService.getByIdWithDish(id);return Result.success(setmealVO);}/*** 修改套餐** @param setmealDTO* @return*/@PutMapping@ApiOperation("修改套餐")@CacheEvict(cacheNames = "setmealCache",allEntries = true)public Result update(@RequestBody SetmealDTO setmealDTO) {setmealService.update(setmealDTO);return Result.success();}/*** 套餐起售停售* @param status* @param id* @return*/@PostMapping("/status/{status}")@ApiOperation("套餐起售停售")@CacheEvict(cacheNames = "setmealCache",allEntries = true)public Result startOrStop(@PathVariable Integer status, Long id) {setmealService.startOrStop(status, id);return Result.success();}
}

缓存套餐——功能测试

测试无误

虽然但是,明明小程序没有显示东西,但是数据还是进了缓存。

 添加购物车——需求分析与设计

产品原型

购物车就是暂时存放所选商品的地方。

没有口味就是直接加入购物车,有口味要先选择口味。

接口设计

 

数据库设计

 冗余字段的存在减少了查询次数。

 添加购物车——代码开发(1)

用到的DTO

 Controller层中

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "C端购物车相关接口")
public class ShoppingCartController {@Autowiredprivate ShoppingCartService shoppingCartService;/*** 添加购物车* @param shoppingCartDTO* @return*/@PostMapping("/add")@ApiOperation("添加购物车")public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){log.info("添加购物车:{}",shoppingCartDTO);shoppingCartService.addShoppingCart(shoppingCartDTO);return Result.success();}
}

Service层中

@Service
@Slf4j
public class ShoppingCartServiceImpl implements ShoppingCartService {@Autowiredprivate ShoppingCartMapper shoppingCartMapper;@Autowiredprivate DishMapper dishMapper;@Autowiredprivate SetmealMapper setmealMapper;/*** 添加购物车* @param shoppingCartDTO*/@Overridepublic void addShoppingCart(ShoppingCartDTO shoppingCartDTO) {//判断当前加入购物车的商品是否存在ShoppingCart shoppingCart = new ShoppingCart();BeanUtils.copyProperties(shoppingCartDTO,shoppingCart); //属性拷贝Long userId = BaseContext.getCurrentId();  //拦截器获取到的用户idshoppingCart.setUserId(userId);List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);//如果已经存在了,只需要将数量加一if(list!=null&&list.size()>0){//这里list要么没有数据,要么只有一条数据ShoppingCart cart = list.get(0);cart.setNumber(cart.getNumber()+1); //update shopping_cart set number=?where id=?shoppingCartMapper.updateNumberById(cart);}else {//如果不存在,需要插入一条购物车数据/*** 判断这次添加到购物车的是菜品还是套餐*/Long dishId = shoppingCartDTO.getDishId();if(dishId!=null){//本次添加是菜品Dish dish = dishMapper.getById(dishId);shoppingCart.setName(dish.getName());shoppingCart.setImage(dish.getImage());shoppingCart.setAmount(dish.getPrice());}else{//本次添加的是套餐Long setmealId = shoppingCartDTO.getSetmealId();Setmeal setmeal = setmealMapper.getById(setmealId);shoppingCart.setName(setmeal.getName());shoppingCart.setImage(setmeal.getImage());shoppingCart.setAmount(setmeal.getPrice());}shoppingCart.setNumber(1);shoppingCart.setCreateTime(LocalDateTime.now());//统一插入数据shoppingCartMapper.insert(shoppingCart);}}
}

Mapper层中

@Mapper
public interface ShoppingCartMapper {/*** 动态条件查询* @param shoppingCart* @return*/List<ShoppingCart> list(ShoppingCart shoppingCart);/*** 根据id修改商品数量* @param shoppingCart*/@Update("update shopping_cart set number = #{number} where id = #{id}")void updateNumberById(ShoppingCart shoppingCart);/*** 插入购物车数据* @param shoppingCart*/@Insert("insert into shopping_cart(name , user_id, dish_id, setmeal_id, dish_flavor, number, amount,image, create_time)" +"values(#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")void insert(ShoppingCart shoppingCart);
}

对应的映射文件

<mapper namespace="com.sky.mapper.ShoppingCartMapper"><select id="list" resultType="com.sky.entity.ShoppingCart">select * from shopping_cart<where><if test="userId != null">and user_id = #{userId}</if><if test="setmealId != null">and setmeal_id = #{setmealId}</if><if test="dishId != null">and dish_id = #{dishId}</if><if test="dishFlavor != null">and dish_flavor = #{dishFlavor}</if></where></select>
</mapper>

 添加购物车——功能测试

前端点击添加成功有新数据

查看购物车——需求分析和设计+代码开发+功能测试

产品原型

 接口设计

Controller中

    /*** 查看购物车* @return*/@GetMapping("/list")@ApiOperation("查看购物车")public Result<List<ShoppingCart>> list(){List<ShoppingCart>list=shoppingCartService.showShoppingCart();return Result.success(list);}

Service中

    /*** 查看购物车* @return*/@Overridepublic List<ShoppingCart> showShoppingCart() {//获取当前微信用户的idLong userId = BaseContext.getCurrentId();ShoppingCart shoppingCart = ShoppingCart.builder().userId(userId).build();List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);return list;}

mapper层已经有了

功能测试

清空购物车——需求分析和设计+代码开发+功能测试

产品原型

店家清空直接删除所有数据

 接口设计

Controller中

    /*** 清空购物车* @return*/@DeleteMapping("/clean")@ApiOperation("清空购物车")public Result clean(){shoppingCartService.cleanShoppingCart();return Result.success();}

Service中

    /*** 清空购物车*/@Overridepublic void cleanShoppingCart() {//获取当前微信用户的idLong userId = BaseContext.getCurrentId();shoppingCartMapper.deleteById(userId);}

mapper中

    /*** 根据用户id删除购物车数据* @param userId*/@Delete("delete from shopping_cart where user_id = #{userId}")void deleteById(Long userId);

功能测试不写了,反正没人看

删除购物车——需求分析与设计

产品原型

点击减号可以减少一个或者是直接删除

 接口设计

 Controller层中

    /*** 删除购物车商品* @param shoppingCartDTO* @return*/@PostMapping("/sub")@ApiOperation("/删除购物车商品")public Result sub(ShoppingCartDTO shoppingCartDTO){log.info("删除商品信息:{}",shoppingCartDTO);shoppingCartService.subShoppingCart(shoppingCartDTO);return Result.success();}

Service层中

    /*** 删除购物车数据* @param shoppingCartDTO*/@Overridepublic void subShoppingCart(ShoppingCartDTO shoppingCartDTO) {ShoppingCart shoppingCart=new ShoppingCart();BeanUtils.copyProperties(shoppingCartDTO,shoppingCart);//获取用户id,查询当前登录用户的idshoppingCart.setId(BaseContext.getCurrentId());List<ShoppingCart> list=shoppingCartMapper.list(shoppingCart);if(list!=null&&list.size()>0){shoppingCart=list.get(0);Integer number = shoppingCart.getNumber();if(number==1){//当前商品在购物车中的份数为1,直接删除当前记录shoppingCartMapper.deleteById2(shoppingCart.getId());}else{//当前商品在购物车中的份数不为1,修改份数即可shoppingCart.setNumber(shoppingCart.getNumber() - 1);shoppingCartMapper.updateNumberById(shoppingCart);}}}

Mapper层中

这个删除是根据id删除,上面的是根据userId删除,两者不同的。

    /*** 根据id删除购物车数据* @param id*/@Delete("delete from shopping_cart where id = #{id}")void deleteById2(Long id);

相关文章:

苍穹外卖day07——缓存菜品套餐+购物车功能实现

缓存菜品——需求设计与分析 问题说明 用户访问量过大带来的一个直接效果就是响应速度慢&#xff0c;使用体验下降。 实现思路 使用redis缓存菜品数据&#xff0c;减少数据库查询操作。 页面展示上基本就是同一个分类在同一页&#xff0c;所以key-value结构可以使用不同的分…...

学习笔记|大模型优质Prompt开发与应用课(二)|第四节:大模型帮你写代码,小白也能做程序

文章目录 01软件开发产业趋势与技术革新软件开发产业趋势与技术革新技术性人才很受欢迎软件开发产业趋势与技术革新技术门槛越来越低 02 大模型驱动的软件开发需求分析prompt 产品设计开发和测试prompt输出回复promptpromptprompt回复 发布和部署promptprompt 维护和更新prompt…...

建造者设计模式 + 高阶函数 => DSL

该设计模式适用于创建复杂对象&#xff0c;该复杂对象通常是由各个部分的子对象用一定的算法或者步骤构成&#xff0c;针对每个子对象内部算法和步骤通常是稳定的&#xff0c;但是该复杂对象的确实由于不同的需求而选择使用不同的子对象进行组装。对于构建该复杂的对象&#xf…...

重学C++系列之智能指针简单介绍

一、什么是智能指针 在使用堆内存时&#xff0c;就像使用栈内存空间一样&#xff0c;可以实现自释放的功能&#xff0c;智能指针在C库中也是类模板之一。 二、智能指针有几种 有四种。auto_ptr, unique_ptr, shared_ptr, weak_ptr 其中后三个是C11支持&#xff0c;第一个已经被…...

LabVIEW开发航天器动力学与控制仿真系统

LabVIEW开发航天器动力学与控制仿真系统 计算机仿真是工程设计和验证的非常有用的工具。它节省了大量的时间、金钱和精力。航天器动力学与控制仿真系统由LabVIEW程序开发&#xff0c;它是模拟航天器等动态系统的有用工具。还可轻松与硬件连接并输出真实信号。 项目采用系统工…...

享元模式——实现对象的复用

1、简介 1.1、概述 当一个软件系统在运行时产生的对象数量太多&#xff0c;将导致运行代价过高&#xff0c;带来系统性能下降等问题。例如&#xff0c;在一个文本字符串中存在很多重复的字符&#xff0c;如果每个字符都用一个单独的对象来表示&#xff0c;将会占用较多的内存…...

【GreenDao】关联表实现,父表关联多个子表

要在GreenDao中实现温湿度采集器表和采集数据表的关联&#xff0c;并在删除温湿度表时同时删除对应的采集数据&#xff0c;可以按照以下步骤进行操作&#xff1a; 在GreenDao的实体类中定义温湿度采集器表&#xff08;Parent Table&#xff09;和采集数据表&#xff08;Child …...

python网站创建005:数据交互

目标&#xff1a;本章讲解不同控件下&#xff0c; 数据在前端和后端之间的交互 控件有&#xff1a; 输入框 密码输入框 单选框 多选框 下拉框 多行文本框 不同控件中如何将数据传入后端&#xff1f;请看一下html代码 <!DOCTYPE html> <html> <head><meta …...

golang 字符串操作、处理

一、golang的字符串长度 1. len()内置系统函数&#xff0c;计算字符串结果是字符串的字节长度&#xff0c;不是字符长度 //1.ASCII字符串长度&#xff08;字节长度&#xff09; str1 : "wo ai zhong guo" fmt.Println(len(str1)) //15//2.带中文的字符串长度&…...

Nginx配置WebSocket反向代理

1、WebSocket协议 ​ WebSocket协议相比较于HTTP协议成功握手后可以多次进行通讯&#xff0c;直到连接被关闭。但是WebSocket中的握手和HTTP中的握手兼容&#xff0c;它使用HTTP中的Upgrade协议头将连接从HTTP升级到WebSocket。这使得WebSocket程序可以更容易的使用现已存在的…...

devops(后端)

1.前言 该devpos架构为gitlabjenkinsharbork8s&#xff0c;项目是java项目&#xff0c;流程为从gitlab拉取项目代码到jenkins&#xff0c;jenkins通过maven将项目代码打成jar包&#xff0c;通过dockerfile构建jdk环境的镜像并把jar包放到镜像中启动&#xff0c;构建好的镜像通…...

Ubuntu安装企业微信

Ubuntu安装企业微信_ubuntu下安装企业微信_星光2020的博客-CSDN博客 在Ubuntu环境安装企业微信可以参考 https://github.com/zq1997/deepin-wine 所述的方法 首先运行 $ wget -O- https://deepin-wine.i-m.dev/setup.sh | sh 然后就可以像安装其它软件一样安装企业微信或其它…...

Prometheus 的应用服务发现及黑河部署等

目录 promtool检查语法 部署Prometheus Server 检查语法是否规范 部署node-exporter 部署Consul 直接请求API进行服务注册 使用register命令注册服务&#xff08;建议使用&#xff09; 单个和多个注册&#xff0c;多个后面多加了s 在Prometheus上做consul的服务发现 部署…...

JAVA SE -- 第十二天

&#xff08;全部来自“韩顺平教育”&#xff09; 常用类 一、包装类 1、包装类的分类 ①针对八种基本数据类型相应的引用类型--包装类 ②有了类的特点&#xff0c;就可以调用类中的方法 ③ 基本数据类型包装类booleanBooleancharCharacterbyteByteshortShortintInteger…...

实战:工作中对并发问题的处理

大家好&#xff0c;我是 方圆。最近在接口联调时发生了数据并发修改问题&#xff0c;我想把这个问题讲解一下&#xff0c;并把当时提出的解决方案进行实现&#xff0c;希望它能在大家以后在遇到同样的问题时提供一些借鉴和思考的方向。原文还是收录在我的 Github: enthusiasm 中…...

腾讯云Cloud Studio:基于Claude快速完成Excel工资自动核算

目录 1 什么是Cloud Studio&#xff1f;2 注册与代码管理2.1 账号注册2.2 Git关联 3 实战&#xff1a;Excel工资自动核算3.1 创建项目与配置3.2 “念咒师”Claude GPT3.3 代码编写与运行 1 什么是Cloud Studio&#xff1f; Cloud Studio是腾讯云为开发者提供的一个基于浏览器的…...

Spring Boot OAuth2 快速入门示例

系统要求 Spring Authorization Server 需要JDK1.8及以上版本。 项目搭建 使用在线项目初始化器 https://start.spring.io/ 生成项目[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ljKbMI4H-1690726855433)(images/screenshot_1690602511482.png)…...

MethodInterceptor

目录 1 MethodInterceptor 1.1 HandleSync 1.2 HandleException 1.3 /// This will be called via Reflection MethodInterceptor HandleSync private void HandleSync(IReadOnlyList<MethodFilterAttribute> filterAttributes, IReadOnlyList<ExceptionFilte…...

PID模块化__以stm32直流电机速度为例

文章目录 前言一、相关PID源码.c.h 二、如何使用1.创建变量2.初始化3.运算4.修改pid参数 总结 前言 本篇使用到的基于这个STM32CubeMX 直流电机PID速度控制、HAL库、cubemx、PID、速度控制、增量式 由于上次使用的pid没有模块化&#xff0c;当多出使用pid的时候就会很麻烦 所以…...

Java ~ Collection/Executor ~ DelayQueue【总结】

前言 文章 相关系列&#xff1a;《Java ~ Collection【目录】》&#xff08;持续更新&#xff09;相关系列&#xff1a;《Java ~ Executor【目录】》&#xff08;持续更新&#xff09;相关系列&#xff1a;《Java ~ Collection/Executor ~ DelayQueue【源码】》&#xff08;学…...

前端高级面试题-安全相关

1 XSS 跨⽹站指令码&#xff08;英语&#xff1a; Cross-site scripting &#xff0c;通常简称为&#xff1a; XSS &#xff09;是⼀种⽹站应⽤程式的安全漏洞攻击&#xff0c;是代码注⼊的⼀种。 它允许恶意使⽤者将程式码注⼊到⽹⻚上&#xff0c;其他使⽤者在观看⽹⻚时就会…...

【前缀和】560.和为 K 的子数组

Halo&#xff0c;这里是Ppeua。平时主要更新C&#xff0c;数据结构算法&#xff0c;Linux与ROS…感兴趣就关注我bua&#xff01; 和为K的子数组 题目:示例:题解&#xff1a;解法一:解法二: 题目: 示例: 题解&#xff1a; 解法一: 暴力解法:我们很容易想到通过两个for循环去遍…...

【Docker】安全及日志管理

安全及日志管理 Docker 安全及日志管理一&#xff1a;Docker 容器与虚拟机的区别1. 隔离与共享2. 性能与损耗 二&#xff1a;Docker 存在的安全问题1.Docker 自身漏洞2.Docker 源码问题 三&#xff1a;Docker 架构缺陷与安全机制1. 容器之间的局域网攻击2. DDoS 攻击耗尽资源3.…...

基于x-scan扫描线的3D模型渲染算法

基于x-scan算法实现的z-buffer染色。c#语言&#xff0c;.net core framework 3.1运行。 模型是读取3D Max的obj模型。 x-scan算法实现&#xff1a; public List<Vertex3> xscan() {List<Vertex3> results new List<Vertex3>();SurfaceFormula formula g…...

LeetCode36.Valid-Sudoku<有效的数独>

题目&#xff1a; 思路&#xff1a; 这题并不难&#xff0c;它类似于N皇后问题。在N皇后问题中&#xff0c;行&#xff0c;列&#xff0c;对角线&#xff0c;写对角线&#xff0c;都不能出现连续的皇后。 本题类似&#xff0c;不过他是行&#xff0c;列&#xff0c;还有一个B…...

Linux中的pause函数

2023年7月29日&#xff0c;周六上午 函数原型 在Linux中&#xff0c;pause()函数用于使当前进程暂停执行&#xff0c;直到接收到一个信号。 #include <unistd.h>int pause(void);pause()函数不接受任何参数。 通常&#xff0c;pause()函数用于编写简单的信号处理程序&…...

CommonCollections6链分析

前面和CC1一样 优点是不限制jdk版本和cc的版本 先开一个ChainedTransformer 然后创LazyMap 我们顺便执行一下避免上面写错 能弹计算器 没问题 后面就是CC6不同的地方了 我们需要一个TiedMapEntry 因为需要一个类调用了get方法 在TiedMapEntry的getValue()方法中调用了get()…...

优化基于tcp,socket的ftp文件传输程序

原始程序&#xff1a; template_ftp_server_old.py&#xff1a; import socket import json import struct import os import time import pymysql.cursorssoc socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST 192.168.31.111 PORT 4101 soc.bind((HOST,PORT)) p…...

MySQL 数据库 【增删查改(二)】

目录 一、表的设计 1、一对一 2、一对多 3、多对多 二、新增 三、查询 1、聚合查询 &#xff08;1&#xff09;聚合函数&#xff1a; &#xff08;2&#xff09; group by 子句 &#xff08;3&#xff09;having 2、联合查询 (1)内连接 (2)外连接 (3)自链接 (4)…...

力扣 -- 978. 最长湍流子数组

一、题目 二、解题步骤 下面是用动态规划的思想解决这道题的过程&#xff0c;相信各位小伙伴都能看懂并且掌握这道经典的动规题目滴。 三、参考代码 class Solution { public:int maxTurbulenceSize(vector<int>& nums) {int nnums.size();vector<int> f(n);…...