mybatis一对多查询返回

  • 定义实体类
  • Mapper.xml文件
  • Mapper.java文件

定义实体类

InventoryVO 和InventoryDetailVO是一对多的关系。

@Data
public class InventoryVO {/**收发 1: 收 0:发**/private String inOrOut;/**发生日期**/private String occTime;private Long storeId;private Long customerId;private String customerName;/**仓库名称**/private String warehouseName;/**业务类型**/private String accountTypeName;/**业务类型**/private int accountType;/** wms单号**/private String wmsBillNo;/**货主单号**/private String cusBillNo;private List<InventoryDetailVO> listDetails;
}
@Data
public class InventoryDetailVO {/** 行号**/private Integer lineNo;/** 货物编码**/private String itemSkuCode;/** 货物名称**/private String itemName;/** 包装数量**/private Integer packageCount;/** 单位名称**/private String unitName;private Long skuId;private String categoryName;
}

Mapper.xml文件

定义一个resullMap,返回类型是type:InventoryVO

<resultMap id="BaseResultMap2" type="com.wms.InventoryVO"><result column="inOrOut" property="inOrOut"/><result column="occTime" property="occTime"/><result column="storeId" property="storeId"/><result column="warehouseName" property="warehouseName"/><result column="accountType" property="accountType"/><result column="wmsBillNo" property="wmsBillNo"/><result column="cusBillNo" property="cusBillNo"/><collection property="listDetails" ofType="com.wms.vo.InventoryDetailVO"><result column="lineNo" property="lineNo"/><result column="itemSkuCode" property="itemSkuCode"/><result column="itemName" property="itemName"/><result column="skuId" property="skuId"/><result column="packageCount" property="packageCount"/><result column="unitName" property="unitName"/></collection></resultMap><select id="statisticsDetails" resultMap="BaseResultMap2">SELECTwlog.create_time AS occTime,temp.`store_id` AS storeId,temp.`account_type` AS accountType,temp.`account_id` AS wmsBillNo,temp.`account_id` AS cusBillNo,temp.type as inOrOut,wlog.`sku_id` AS skuId,wlog.`change_count_total` AS packageCountFROM(SELECTcustomer_id, store_id,account_id, account_type,  typeFROM  warehouse_inventory_log lGROUP BY customer_id, store_id,account_id, account_type,  type) tempINNER JOIN warehouse_inventory_log wlogON temp.account_id = wlog.`account_id`AND temp.account_type = wlog.`account_type`<where><if test="storeId != null">temp.`store_id` = #{storeId}</if><if test="skuIdList != null">and sku_id in<foreach collection="skuIdList" open="(" separator="," close=")" item="item">#{item}</foreach></if><if test="customerId != null">and customer_id = #{customerId}</if><if test="startTime != null">and create_time >= #{startTime}</if><if test="endTime != null">and create_time <![CDATA[<=]]> #{endTime}</if><if test="type != null">and temp.type = #{type}</if></where></select>

Mapper.java文件

List<InventoryVO> statisticsDetails(WarehouseInventoryLogDTO warehouseInventoryLogDTO);
@Data
public class WarehouseInventoryLogDTO  extends Pager {private Long customerId;private String skuName;private String startTime;private String endTime;private List<Long> skuIdList;private Long storeId;private Integer type;
}

mybatis一对多查询返回相关推荐

  1. PageHelper关于Mybatis一对多查询返回Total错误

    PageHelper关于Mybatis一对多查询返回Total错误 遇到的问题: pagehelper进行一对多查询时,返回的总数量对不上,例如需求是一个页面展示10个spu信息,实际上只展示了6个s ...

  2. Mybatis 一对多查询返回结果只有一条:解决思路

    使用的ssm框架: 首先上xml配置文件信息: </resultMap><resultMap id="userMap" type="User" ...

  3. mybatis 一对多查询 按结果嵌套处理、按查询嵌套处理,以及两者之间的区别

    mybatis 一对多查询 按结果嵌套处理.按查询嵌套处理 最近用到一对多查询,记录一下 实体类 public class RegionEntity implements Serializable { ...

  4. Mybatis一对多查询的两种姿势,你值得拥有(收藏就完事了)

    文章目录 数据库表准备 实例演示 方法一:联合查询ResultMap映射 方法二:子查询映射 总结 前言 最近碰到了Mybatis一对多查询的场景,在这里总结对比下常见的两种实现方式. 本文以常见的订 ...

  5. Mybatis一对多查询(附带多条件查询)

    场景:现有两张表 s_class(班级表) s_student(学生表) 需求:查询出班级和班级下的学生 分析:首先班级和学生是一对多的关系,一个班级对应多个学生 实现方法: 方法一:通过查出班级,再 ...

  6. mybatis一对多查询

    一.一对多查询 A表与B表是一对多关系: A表 a ad 1 1 B表 b a_id 1 1 2 1 3 1 A表对应的实体类EntityA,B表对应的实体类EntityB public class ...

  7. MyBatis研习录(09)——MyBatis一对多查询

    C语言自学完备手册(33篇) Android多分辨率适配框架 JavaWeb核心技术系列教程 HTML5前端开发实战系列教程 MySQL数据库实操教程(35篇图文版) 推翻自己和过往--自定义View ...

  8. mybatis一对多查询的两种方式

    user 和order 对象 package com.itheima.mybatis.pojo;import java.io.Serializable; import java.util.Date;p ...

  9. mybatis一对多查询Pagehelper分页条数不对

    问题:在写mybatis一对多的时候用到了Pagehelper进行分页,然后发现确实能分页,但是展示的条数不对,后来研究了发现原来Pagehelper插件在一对多查询的时候默认的是对多的一方进行的分页 ...

最新文章

  1. 后端开发实践:Spring Boot项目模板
  2. centos7 安装mysql5.6_centos7安装mysql5.6
  3. 【Envi风暴】Envi 5.3 SP1经典安装手把手图文教程(含补丁文件)
  4. windows 使用qtcreater编译boost 测试
  5. 第一范式转化为第二范式_深度解读《中国智能经济发展白皮书》:AI为核心驱动力,百度给出智能范式...
  6. android 挖孔屏适配_小米公布安卓Q升级适配计划,共11款机型
  7. 什么是Semantic(语义)?从互联网爬虫、自动驾驶到对话机器人
  8. gerrit权限控制
  9. 深入解读Linux进程调度系列——数据结构解析
  10. 零成本、零流量,我是如何空手反套白狼?
  11. Java8新特性 方法引用(二)
  12. vue+echarts+springboot实现云词图
  13. docker学习1--docker基础学习
  14. C语言Qt视图实现彩虹渐变效果,我就问你6不6?
  15. TP框架中S函数使用方法
  16. 拼多多——多多的数字组合
  17. 8255A的工作方式
  18. 多边形区域填充算法--扫描线种子填充算法
  19. hMailServer设置
  20. 4种高速安全混合云解决方案,助力您的云迁移之旅

热门文章

  1. url参数值中有+、空格、%20、%2b
  2. Opencv学习笔记(二) 提取图像中的水平线和垂直线
  3. linux中文镜像文件iso下载地址,linux系统镜像iso文件下载
  4. C语言代码优化的实用方法大总结
  5. IE9 已停止工作 的解决办法
  6. HTML旋转的太极图
  7. 计算机维修人员评价表,信息技术课学生评价表
  8. 支付功能如何进行测试
  9. Centos7 卸载 Nginx 并重新安装 Nginx
  10. 马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup