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

Mybatis-plus-Join--分页查询

数据表四张:

user: id,username,create_time,update_time

product: id,name,price,number(库存),create_time,update_times

order: id,quantity,order_time(下单时间),update_time

order_detail:id,product_id,order_id,quantity,price,create_time,update_time

1、UserService接口:

List<UserDTO> selectAll(int pageNum, int pageSize);

 2、封装的UserDTO类(想在前端展示什么内容,就封装什么属性)

 

package com.xxxx.DTO;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.xxxx.entity.OrderDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import java.time.LocalDateTime;
import java.util.List;
@Data
public class OrderDTO {@ApiModelProperty(value = "订单ID")@TableId(value = "id", type = IdType.AUTO)private Integer id;@ApiModelProperty(value = "订单数量")private Integer quantity;@ApiModelProperty(value = "下单时间")@TableField(fill = FieldFill.INSERT ,value = "order_time")private LocalDateTime orderTime;@ApiModelProperty(value = "修改时间")@TableField(fill = FieldFill.INSERT_UPDATE ,value = "update_time")private LocalDateTime updateTime;@ApiModelProperty(value = "用户id")@TableField(value = "user_id")private Integer userId;/*** 订单和订单详情是一对多*/private List<OrderDetail> orderDetailList;

3、重点:UserServiceImpl 中的实现逻辑

注入:

@Autowired
private UserMapper userMapper;
 @Overridepublic List<UserDTO> selectAll(int pageNum, int pageSize) {//用户: 订单   1: n//订单 : 订单详情 1: n//订单详情 : 商品 1: 1MPJLambdaWrapper<User> wrapper=new MPJLambdaWrapper<>(User.class).selectAll(User.class)//用户: 订单   1: n.selectCollection(OrderDetail.class,UserDTO::getOrderDetailList).leftJoin(Order.class,Order::getUserId,User::getId).leftJoin(OrderDetail.class,OrderDetail::getOrderId,Order::getId);return userMapper.selectJoinList(UserDTO.class,wrapper);}

 4、UserControler

    @Resourceprivate UserService userService;/*** 分页查询所有用户及详情*/@PostMapping("selectAllPage")public List<UserDTO> selectByPage(int pageNum, int pageSize){return userService.selectAll(pageNum,pageSize);}

5、再PostMan中测试

访问路径:http://localhost:9999/springboot_mp/selectAllPage?pageNum=1&pageSize=3

[
    {
        "id": 1,
        "username": "张三",
        "orderDetailList": [
            {
                "id": 1,
                "productId": 1,
                "orderId": 1,
                "quantity": 3,
                "price": 3000.00,
                "createTime": "2024-12-17T15:24:20",
                "updateTime": "2024-12-17T15:24:20"
            },
            {
                "id": 2,
                "productId": 3,
                "orderId": 1,
                "quantity": 1,
                "price": 2300.00,
                "createTime": "2024-12-17T15:24:20",
                "updateTime": "2024-12-17T15:24:20"
            },
            {
                "id": 5,
                "productId": 1,
                "orderId": 3,
                "quantity": 9,
                "price": 3000.00,
                "createTime": "2024-12-17T15:25:55",
                "updateTime": "2024-12-17T15:25:55"
            },
            {
                "id": 6,
                "productId": 3,
                "orderId": 3,
                "quantity": 10,
                "price": 2300.00,
                "createTime": "2024-12-17T15:25:55",
                "updateTime": "2024-12-17T15:25:55"
            }
        ]
    }
]

 

http://www.lryc.cn/news/507064.html

相关文章:

  • 对BG兼并点的理解-不断刷新版
  • python的游标是什么
  • 硬件---14---PCB学习:PCB封装库及布局操作
  • 什么是MyBatis
  • 开发技术-Java改变图片格式
  • 基于DockerCompose搭建Redis主从哨兵模式
  • aioice里面candidate固定UDP端口测试
  • Git使用教程-分支使用/合并分支提交
  • 单元测试使用记录
  • LabVIEW实时信号采集与频谱分析
  • OpenCV(python)从入门到精通——运算操作
  • 基础2:值类型与右值引用
  • GitHub年度报告发布!Python首次超越JavaScript
  • EdgeX Message Bus 消息总线
  • 【JavaEE进阶】关于Maven
  • YOLOv9-0.1部分代码阅读笔记-autoanchor.py
  • Electronjs+Vue如何开发PC桌面客户端(Windows,Mac,Linux)
  • 谷歌浏览器 安装谷歌浏览器特定版本后禁止自动更新
  • Linux计算时间差
  • Python的3D可视化库【vedo】2-5 (plotter模块) 坐标转换、场景导出、添加控件
  • 【VUE】13、安装nrm管理多个npm源
  • 【SQL/MySQL 如何使用三种触发器】SQL语句实例演示
  • Docker容器五种网络驱动模式详解
  • netfilter简介及流程图
  • Vue 前端代码规范
  • JAVA:组合模式(Composite Pattern)的技术指南
  • js常用方法之: 预览大图(uniapp原生方法封装)
  • python 高级用法
  • TISAX认证最新消息
  • Python中所有子图标签Legend显示详解