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

小学的门户网站建设纷享销客官网

小学的门户网站建设,纷享销客官网,建站快车官网,公司网站怎么做包括什么目录 菜品分页查询 需求分析和设计 代码开发 设计DTO类 设计VO类 Controller层 Service层接口 Service层实现类 Mapper层 功能测试 删除菜品 需求设计和分析 代码开发 Controller层 Service层接口 Service层实现类 Mapper层 功能测试 修改菜品 需求分析和设…目录 菜品分页查询 需求分析和设计 代码开发 设计DTO类 设计VO类 Controller层 Service层接口 Service层实现类 Mapper层 功能测试 删除菜品 需求设计和分析 代码开发 Controller层 Service层接口 Service层实现类 Mapper层 功能测试 修改菜品 需求分析和设计 代码开发 根据id查询菜品实现 Controller层 Service层接口 Service层实现类 Mapper层 修改菜品实现 Controller层 Service层接口 Service层实现类 Mapper层 功能测试 1--苍穹外卖-SpringBoot项目介绍及环境搭建 详解-CSDN博客 2--苍穹外卖-SpringBoot项目中员工管理 详解一-CSDN博客 3--苍穹外卖-SpringBoot项目中员工管理 详解二-CSDN博客 4--苍穹外码-SpringBoot项目中分类管理 详解-CSDN博客 5--苍穹外卖-SpringBoot项目中菜品管理 详解一-CSDN博客 6--苍穹外卖-SpringBoot项目中菜品管理 详解二-CSDN博客 7--苍穹外卖-SpringBoot项目中套餐管理 详解一-CSDN博客 8--苍穹外卖-SpringBoot项目中套餐管理 详解二-CSDN博客 9--苍穹外卖-SpringBoot项目中Redis的介绍及其使用实例 详解-CSDN博客 菜品分页查询 需求分析和设计 业务规则 根据页码展示菜品信息 每页展示10条数据 分页查询时可以根据需要输入菜品名称、菜品分类、菜品状态进行查询 代码开发 设计DTO类 根据菜品分页查询接口定义设计对应的DTO 在sky-pojo模块中 package com.sky.dto;import lombok.Data;import java.io.Serializable;Data public class DishPageQueryDTO implements Serializable {private int page;private int pageSize;private String name;//分类idprivate Integer categoryId;//状态 0表示禁用 1表示启用private Integer status;}设计VO类 根据菜品分页查询接口定义设计对应的VO在返回的数据中categoryName属于另外一个文件中需要使用VO转换属性为json方便前端展示 在sky-pojo模块中 package com.sky.vo;import com.sky.entity.DishFlavor; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List;Data Builder NoArgsConstructor AllArgsConstructor public class DishVO implements Serializable {private Long id;//菜品名称private String name;//菜品分类idprivate Long categoryId;//菜品价格private BigDecimal price;//图片private String image;//描述信息private String description;//0 停售 1 起售private Integer status;//更新时间private LocalDateTime updateTime;//分类名称private String categoryName;//菜品关联的口味private ListDishFlavor flavors new ArrayList();//private Integer copies; }Controller层 根据接口定义创建DishController的page分页查询方法 //菜品分页查询GetMapping(/page)ApiOperation(菜品分页查询)public ResultPageResult page(DishPageQueryDTO dishPageQueryDTO){log.info(菜品分页查询{},dishPageQueryDTO);PageResult pageResultdishService.pageQuery(dishPageQueryDTO);return Result.success(pageResult);} Service层接口 在 DishService 中扩展分页查询方法 //菜品分页查询PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO); Service层实现类 在 DishServiceImpl 中实现分页查询方法 //菜品分页查询Overridepublic PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {PageHelper.startPage(dishPageQueryDTO.getPage(),dishPageQueryDTO.getPageSize());PageDishVO page dishMapper.pageQuery(dishPageQueryDTO);return new PageResult(page.getTotal(),page.getResult());} Mapper层 在 DishMapper 接口中声明 pageQuery 方法 //菜品分页查询PageDishVO pageQuery(DishPageQueryDTO dishPageQueryDTO); 在 DishMapper.xml 中编写SQL select idpageQuery resultTypecom.sky.vo.DishVOselect d.* ,c.name as categoryName from dish d left outer join category c on d.category_idc.idwhereif testname!nulland d.name like concat(%,#{name},%)/ifif testcategoryId!nulland d.category_id#{categoryId}/ifif teststatus!nulland d.status#{status}/if/whereorder by d.create_time desc/select 功能测试 删除菜品 需求设计和分析 业务规则 可以一次删除一个菜品也可以批量删除菜品 起售中的菜品不能删除 被套餐关联的菜品不能删除 删除菜品后关联的口味数据也需要删除掉 代码开发 Controller层 根据删除菜品的接口定义在DishController中创建方法 //菜品批量删除DeleteMappingApiOperation(菜品批量删除)public ResultString delete(RequestParam ListLong ids){//RequestParam注解使用mvc框架可以获取到参数123中的变量值log.info(菜品批量删除{},ids);dishService.deleteBatch(ids);return Result.success();} Service层接口 在DishService接口中声明deleteBatch方法 //菜品批量删除void deleteBatch(ListLong ids); Service层实现类 在DishServiceImpl中实现deleteBatch方法 //菜品批量删除Transactional//事务public void deleteBatch(ListLong ids) {//判断当前菜品是否能够删除---是否存在起售中的菜品for (Long id : ids) {//根据主键查询菜品Dish dishdishMapper.getById(id);//查询是否起售if (Objects.equals(dish.getStatus(), StatusConstant.ENABLE)){//当前菜品处于起售中不能删除throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);}}//判断当前菜品是否能够删除---是否被套餐关联了ListLong setmealIdssetmealDishMapper.getSetmealIdsByDishIds(ids);if (setmealIds!null !setmealIds.isEmpty()){//当前菜品被套餐关联了不能删除throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);}//删除菜品表中的菜品数据for (Long id : ids) {dishMapper.deleteById(id);//删除菜品关联的口味数据dishFlavorMapper.deleteByDishId(id);} Mapper层 在DishMapper中声明getById方法并配置SQL //根据主键查询菜品Select(select *from dish where id#{id})Dish getById(Long id); 创建SetmealDishMapper声明getSetmealIdsByDishIds方法并在xml文件中编写SQL package com.sky.mapper;import org.apache.ibatis.annotations.Mapper;import java.util.List;Mapper public interface SetmealDishMapper {//根据菜品id查询对应的套餐idListLong getSetmealIdsByDishIds(ListLong dishIds);}SetmealDishMapper.xml ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.sky.mapper.SetmealDishMapperselect idgetSetmealIdsByDishIds resultTypejava.lang.Longselect setmeal_id from setmeal_dish where dish_id inforeach collectiondishIds itemdishId separator, open( close)#{dishId}/foreach/select /mapper 在DishMapper.java中声明deleteById方法并配置SQL //根据主键删除菜品数据Delete(delete from dish where id#{id})void deleteById(Long id); 在DishFlavorMapper中声明deleteByDishId方法并配置SQL //根据菜品id删除对应的口味数据Delete(delete from dish_flavor where dish_id#{dishId})void deleteByDishId(Long dishId); 性能优化 在DishServiceImpl中删除菜品是一条一条传送执行的大大降低了执行效率原代码如下 //删除菜品表中的菜品数据for (Long id : ids) {dishMapper.deleteById(id);//删除菜品关联的口味数据dishFlavorMapper.deleteByDishId(id);} 为了提高性能进行修改使用动态sql执行删除操作 //根据菜品id集合批量删除菜品数据//sql:delete from dish where id in(?,?,?)dishMapper.deleteByIds(ids);//根据菜品id集合批量删除关联的口味数据//sql:delete from dish_flavor where dish_id in(?,?,?)dishMapper.deleteByDishIds(ids); 在DishMapper中 //根据菜品id集合批量删除菜品void deleteByIds(ListLong ids);//根据菜品id集合批量删除关联的口味数据void deleteByDishIds(ListLong dishId); 在DishMapper.xml中 delete iddeleteByIdsdelete from dish where id inforeach collectionids open( separator, close) itemid#{id}/foreach/deletedelete iddeleteByDishIdsdelete from dish_flavor where dish_id inforeach collectiondishIds open( close) separator, itemdishId#{dishId}/foreach/delete 功能测试 进行前后端联调删除成功 修改菜品 需求分析和设计 接口 根据id查询菜品 根据类型查询分类(已实现) 文件上传(已实现) 修改菜品 代码开发 根据id查询菜品实现 Controller层 根据id查询菜品的接口定义在DishController中创建方法 //根据id查询菜品GetMapping(/{id})ApiOperation(根据id查询菜品)public ResultDishVO getById(PathVariable Long id){log.info(根据id查询菜品{},id);DishVO dishVOdishService.getByIdWithFlavor(id);return Result.success(dishVO);} Service层接口 在DishService接口中声明getByIdWithFlavor方法 //根据id查询菜品和对应的口味数据DishVO getByIdWithFlavor(Long id); Service层实现类 在DishServiceImpl中实现getByIdWithFlavor方法 //根据id查询菜品和对应的口味数据Overridepublic DishVO getByIdWithFlavor(Long id) {//根据id查询菜品数据Dish dishdishMapper.getById(id);//根据菜品id查询口味数据ListDishFlavor dishFlavorsdishFlavorMapper.getByDishId(id);//将查询到的数据封装到VODishVO dishVO new DishVO();BeanUtils.copyProperties(dish,dishVO);dishVO.setFlavors(dishFlavors);return dishVO;} Mapper层 在DishFlavorMapper中声明getByDishId方法并配置SQL //根据id查询对应的口味数据Select(select *from dish_flavor where dish_id#{dishId})ListDishFlavor getByDishId(Long dishId); 修改菜品实现 Controller层 根据修改菜品的接口定义在DishController中创建方法 //修改菜品PutMappingApiOperation(修改菜品)public ResultString update(RequestBody DishDTO dishDTO){log.info(修改菜品{},dishDTO);dishService.updateWithFlavor(dishDTO);return Result.success();} Service层接口 在DishService接口中声明updateWithFlavor方法 //根据id修改菜品基本信息和对应的口味数据void updateWithFlavor(DishDTO dishDTO); Service层实现类 在DishServiceImpl中实现updateWithFlavor方法 //根据id修改菜品基本信息和对应的口味信息Overridepublic void updateWithFlavor(DishDTO dishDTO) {Dish dish new Dish();BeanUtils.copyProperties(dishDTO,dish);//修改菜品表基本信息dishMapper.update(dish);//删除原有的口味数据dishFlavorMapper.deleteByDishId(dishDTO.getId());//重新插入口味数据ListDishFlavor flavors dishDTO.getFlavors();if (flavors!null !flavors.isEmpty()){flavors.forEach(dishFlavor - {dishFlavor.setDishId(dishDTO.getId());});//向口味表插入n条数据dishFlavorMapper.insertBatch(flavors);}} Mapper层 在DishMapper中声明update方法 //根据id动态修改菜品数据AutoFill(value OperationType.UPDATE)void update(Dish dish); 并在DishMapper.xml文件中编写SQL: update idupdateupdate dishsetif testname!nullname#{name},/ifif testcategoryId!nullcategory_id#{categoryId},/ifif testprice!nullprice#{price},/ifif testimage!nullimage#{image},/ifif testdescription!nulldescription#{description},/ifif teststatus!nullstatus#{status},/ifif testupdateTime!nullupdate_time#{updateTime},/ifif testupdateUser!nullupdate_user#{updateUser},/if/setwhere id#{id}/update 功能测试
http://www.w-s-a.com/news/462194/

相关文章:

  • 龙华做网站联系电话北京软件开发培训班
  • 做网站运营有前途网站的建设与管理的心得体会
  • 河南网站推广怎么做网页制作免费下载
  • 网站如何屏蔽中国ip商丘网站建设的公司哪家好
  • 东莞广告公司东莞网站建设价格鹤壁哪有做网站的
  • 门户网站界面设计logo设计商标设计
  • 建设银行网站驱动宁波网站建设相信荣胜网络
  • 八里河网站建设项目建设可行性企业品牌推广方式有哪些
  • jsp网站开发之html入门知识广州服装设计公司
  • 做电商看的网站有哪些个人网页制作成品免费
  • 沈阳建站多少钱境外网站 备案
  • 提交网站收录入口斗图在线制作
  • 建设化妆品网站服务医药网站前置审批
  • 购物网站修改注册信息模块的分析怎么注册公司logo
  • 那个网站可以做域名跳转的青岛网站建设定制
  • 网站登记模板互联网技术发展及其影响的调查
  • 北京专业的网站建设西安企业家名单
  • 移动网站开发服务器丰都集团网站建设
  • 网站开发逻辑图烫画图案设计网站
  • 客户管理系统哪找公司网站如何做优化
  • 常德企业网站建设广州站在哪里
  • 移动端网站建站视频教程网站如何做淘客
  • 注册网站会不会有风险网站建设实训致谢语
  • ssh框架做的家政服务网站需要做网站建设的公司
  • 众筹网站制作长春高端网站建设
  • 亳州网站网站建设wordpress汉化.po
  • 怎样给建设的网站提意见网红营销概念
  • 怎么知道一个网站是谁做的广告行业网
  • 上海app定制开发公司大城网站优化
  • 工厂 网站建设北京招聘网站设计师