【外卖系统】菜品信息分页查询

news/2024/10/17 12:28:59/

需求分析

当菜品数据很多时,用分页的形式来展示列表数据

代码开发

  • 页面发送ajax请求,将分页查询参数提交到服务端,获取分页数据
  • 页面发送请求,请求服务端进行图片下载,用于页面图片展示

构造分页

注意:
在这里插入图片描述这里不能直接返回,否则分页查询显示的信息不是完整的。比如要展示菜品名称,返回的数据是没有菜品名称的。
在这里插入图片描述后端返回的数据中,也需要有categoryName这个数据
在这里插入图片描述

package com.springboot.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.reggie.common.R;
import com.springboot.reggie.dto.DishDto;
import com.springboot.reggie.entity.Category;
import com.springboot.reggie.entity.Dish;
import com.springboot.reggie.entity.DishFlavor;
import com.springboot.reggie.service.CategoryService;
import com.springboot.reggie.service.DishFlavorService;
import com.springboot.reggie.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.stream.Collectors;/*** 菜品管理*/
@RestController
@RequestMapping("/dish")
@Slf4j
public class DishController {@Autowiredprivate DishService dishService;//菜品服务@Autowiredprivate DishFlavorService dishFlavorService;//菜品口味@Autowiredprivate CategoryService categoryService;//菜品分类@PostMappingpublic R<String> save(@RequestBody DishDto dishDto)//记得封装要加RequestBody注解{log.info(dishDto.toString());dishService.saveWithFlavor(dishDto);return R.success("新增菜品成功...");}/*** 菜品信息分页查询* @param page* @param pageSize* @param name* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize,String name){//构造分页构造器对象Page<Dish> pageInfo = new Page<>(page,pageSize);Page<DishDto> dishDtoPage = new Page<>();//条件构造器LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();//添加过滤条件//使用模糊查询queryWrapper.like(name != null,Dish::getName,name);//添加排序条件 根据更新时间进行降序排序queryWrapper.orderByDesc(Dish::getUpdateTime);//执行分页查询dishService.page(pageInfo,queryWrapper);//将上面pageInfo对象中的属性拷贝到dishDtoPage中去BeanUtils.copyProperties(pageInfo,dishDtoPage,"records");List<Dish> records = pageInfo.getRecords();List<DishDto> list =  records.stream().map((item)->{DishDto dishDto = new DishDto();BeanUtils.copyProperties(item,dishDto);Long categoryId  =  item.getCategoryId();//分类id//根据id查询分类对象Category category =  categoryService.getById(categoryId);if(category != null){String categoryName = category.getName();dishDto.setCategoryName(categoryName);}String categoryName = category.getName();dishDto.setCategoryName(categoryName);return  dishDto;}).collect(Collectors.toList());//  List<DishDto> list = null;dishDtoPage.setRecords(list);return R.success(pageInfo);}}

http://www.ppmy.cn/news/998268.html

相关文章

2023年7月CSDN客服月报|解决3个重大问题和25个次要问题,处理4个用户需求及建议

听用户心声&#xff0c;解用户之需。hello&#xff0c;大家好&#xff0c;这里是《CSDN客诉报告》第22期&#xff0c;接下来就请大家一同回顾我们7月份解决的bug&#xff5e; 一、重大问题 1、【小程序】会员小程序签到余额及转盘余额未到账 反馈量&#xff1a;14 问题描述…

opencv04-掩膜

opencv04-掩膜 抠图 #include <iostream> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> #include <vector> #include <array> #include <algorithm>using namespace std; using namespace cv;int main() {str…

P3373 【模板】线段树 2(乘法与加法)(内附封面)

【模板】线段树 2 题目描述 如题&#xff0c;已知一个数列&#xff0c;你需要进行下面三种操作&#xff1a; 将某区间每一个数乘上 x x x&#xff1b;将某区间每一个数加上 x x x&#xff1b;求出某区间每一个数的和。 输入格式 第一行包含三个整数 n , q , m n,q,m n,…

aws中opensearch 日志通(Centralized Logging with OpenSearch)2.0(一)

aws日志通2.0 实现全面的日志管理和分析功能 一体化日志摄取 &#xff1a;把aws服务器日志和应用日志传输到opensearch域中无代码日志处理 &#xff1a;在网页控制台中就可以实现数据处理开箱即用 &#xff1a;提供可视化模版&#xff08;nginx、HTTP server &#xff09; 架构…

自定义MVC增删改查

目录 mymvcdemo是自定义mvc框架的使用示例 1.1 实体类 1.2 dao方法 1.3 写Service / biz 三层架构 1.4 建action 相当于selvert 1.5 con连接MySQL 8.0 版本 1.6 配置文件 XML 1.7 主界面布局 1.8 增加界面布局 1.9 写tld配置文件 2.0 注意架包 我是已经打包好的 mymv…

Expectation (Easy Version) 2023“钉耙编程”中国大学生算法设计超级联赛(5)hdu7330

Problem - 7330 题目大意&#xff1a;有n次游戏&#xff0c;每次游戏有a/b的概率获胜&#xff0c;且相互独立&#xff0c;如果当前赢了cnt次游戏&#xff0c;那么这次游戏会赢得的分数&#xff0c;问最后得分的期望 1<n<1e6;1<m,a<b<998244353 思路&#xff…

PHP高级检索功能的实现以及动态拼接sql

我们学习了解了这么多关于PHP的知识&#xff0c;不知道你们对PHP高级检索功能的实现以及动态拼接sql是否已经完全掌握了呢&#xff0c;如果没有&#xff0c;那就跟随本篇文章一起继续学习吧! PHP高级检索功能的实现以及动态拼接sql。完成的功能有&#xff1a;可以单独根据一个…

开源项目-知识库管理系统(中国软件杯项目)

简述 哈喽,大家好,今天带来一个开源项目-知识库管理系统,项目通过Spring MVC技术实现。通过readme了解到这是某位大神大三暑假(2016年)参加第五届中国软件杯项目的源码。由三人团队完成(Yu yufeng\Zhou changqin\Liu chenzhe) 此作品获得了本科组全国二等奖。项目本身用…