解決 mybatis一對多分頁問題 聯級查詢
顯示總訂單下的子訂單並且條件包含總訂單條件 和子訂單條件
VO
@ApiModelProperty(value = "訂單id")
private Integer orderId;
@ApiModelProperty(value = "訂單狀態")
private Integer status;
@ApiModelProperty(value = "實付(總計)")
private Integer realPay;
@ApiModelProperty(value = "下單時間(訂單詳情專用欄位)")
@JsonFormat(pattern = "yyyy-MM-dd:HH:mm:ss",timezone = "Asia/Shanghai")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createdAt;
@ApiModelProperty(value = "取消時間(訂單詳情專用欄位)")
@JsonFormat(pattern = "yyyy-MM-dd:HH:mm:ss",timezone = "Asia/Shanghai")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime cancelAt;
@ApiModelProperty(value = "完成時間(訂單詳情專用欄位)")
@JsonFormat(pattern = "yyyy-MM-dd:HH:mm:ss",timezone = "Asia/Shanghai")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime receivingAt;
@ApiModelProperty(value = "子訂單資訊")
private List<StallSubOrderVO> subOrderList;
返回值 XML
column="{orderId=orderId,stallId=stallId,subOrderStatus=subOrderStatus} 一定要對應上你的條件
<resultMap id="resultOrderByStallMap" type="StallOrderVO">
<id column="orderId" property="orderId"/>
<result column="status" property="status"/>
<result column="realPay" property="realPay"/>
<collection property="subOrderList" column="{orderId=orderId,stallId=stallId,subOrderStatus=subOrderStatus}"
select="getSubList"/>
</resultMap>
總訂單 xml
<select id="getOrderListByStall" resultMap="resultOrderByStallMap">
select o.id as orderId,o.`status`, o.real_pay as realPay, ${stallId} as stallId ,'${subOrderStatus}' as subOrderStatus
from `order` as o
where
<if test="orderStatus != null">
o.`status` in
<foreach item="orderItem" collection="orderStatus" index="index" open="(" separator="," close=")">
#{orderItem}
</foreach>
and
</if>
o.id in(
select DISTINCT so.order_id
from sub_order as so
where so.order_id = o.id and so.stall_owner_id = #{stallId} and so.is_ready = false and so.`status` in (${subOrderStatus})
)
order by o.updated_at desc
</select>
子訂單
<select id="getSubList" resultType="com.deepmedical.freshfood.http.res.stall.StallSubOrderVO">
select id as suborderId,is_ready as isReady,dishes_name as dishesName, sku_spec as
skuSpec, sku_price as skuPrice, amount
from sub_order
where order_id = #{orderId} and stall_owner_id = #{stallId} and is_ready = false
<if test="subOrderStatus != null and subOrderStatus.length > 0">
and `status` in (#{subOrderStatus})
</if>
</select>
service(用的mybatis-plus 直接分頁)
Page page = new Page(orderForm.getPageNum(), orderForm.getPageSize());
List orderList = baseMapper.getOrderListByStall(page, stallId, orderStatus,sb.toString());
page.setRecords(orderList);
return PageUtil.getPage(page.getRecords(), page.getTotal());
相關文章
- Mybatis plus 一對多關聯查詢分頁不準確的問題MyBatis
- MyBatis初級實戰之五:一對一關聯查詢MyBatis
- Mybatis【15】-- Mybatis一對一多表關聯查詢MyBatis
- MyBatis初級實戰之六:一對多關聯查詢MyBatis
- MyBatis千萬級資料查詢解決方案,避免OOMMyBatisOOM
- MyBatis(六) sql片段定義、級聯查詢、巢狀查詢MyBatisSQL巢狀
- 教你如何使用PyTorch解決多分類問題PyTorch
- sql一關聯多查詢時否定篩選出現的問題的解決SQL
- 如何寫一對多分頁的SQLSQL
- leetcode題解(查詢表問題)LeetCode
- 優化-mysql子查詢索引失效問題解決優化MySql索引
- 兩表關聯查詢:sql、mybatisSQLMyBatis
- MyBatis 查詢資料時屬性中多對一的問題(多條資料對應一條資料)MyBatis
- mybatis 對特殊字元的模糊查詢MyBatis字元
- mybatis多表聯合查詢的寫法MyBatis
- MyBatis使用四(查詢詳解)MyBatis
- Laravel 關聯查詢 ——一對一 簡單例子Laravel單例
- 深入sql多表差異化聯合查詢的問題詳解SQL
- mybatis基礎系列(四)——關聯查詢、延遲載入、一級快取與二級快取MyBatis快取
- spring data jpa 多對一聯表查詢Spring
- 查詢效率提升10倍!3種優化方案,幫你解決MySQL深分頁問題優化MySql
- spring data jpa關聯查詢(一對一、一對多、多對多)Spring
- Mybatis查詢MyBatis
- mybatis一對多查詢resultMap只返回了一條記錄MyBatis
- Spring Boot整合Mybatis完成級聯一對多CRUD操作Spring BootMyBatis
- #MyBatis多表查詢 #多對一、一對多的兩種實現方式 @FDDLCMyBatis
- prometheus 問題排查 grafana頁面資訊查詢不全PrometheusGrafana
- 一對多分頁的SQL到底應該怎麼寫?SQL
- MyBatis 解決欄位名不一致的問題MyBatis
- Mybatis分頁外掛只顯示第一頁的問題MyBatis
- 一個MySQL多表查詢的問題MySql
- 流式查詢1. mybatis的遊標Cursor,分頁大資料查詢MyBatis大資料
- Mybatis-技術專區-如何清晰的解決出現「多對一模型」和「一對多模型」的問題MyBatis模型
- 解決pod健康檢查問題
- springDataJpa多表級聯查詢(@ManyToOne @OneToOne)Spring
- Mybatis 一級快取和引發的問題MyBatis快取
- MySQL 優化五(關聯查詢子查詢以及 in 的效率問題)(高階篇)MySql優化
- Oracle:sqlplus查詢出的中文是亂碼問題的解決(轉)OracleSQL