解決 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
- Hibernate 一對多配置 級聯操作(級聯失敗問題分析解決)
- MyBatis(六) sql片段定義、級聯查詢、巢狀查詢MyBatisSQL巢狀
- MyBatis千萬級資料查詢解決方案,避免OOMMyBatisOOM
- MyBatis關聯查詢MyBatis
- Oracle分頁查詢中排序與效率問題解決方法詳解Oracle排序
- MyBatis 多表聯合查詢,欄位重複的解決方法MyBatis
- plsql查詢亂碼問題解決SQL
- 批次分頁查詢問題?
- sql一關聯多查詢時否定篩選出現的問題的解決SQL
- MyBatis基礎:MyBatis關聯查詢(4)MyBatis
- 如何寫一對多分頁的SQLSQL
- 教你如何使用PyTorch解決多分類問題PyTorch
- 求助:DetachedCriteria關聯查詢問題~~
- 分頁查詢的排序問題排序
- 批次查詢的翻頁問題
- 兩表關聯查詢:sql、mybatisSQLMyBatis
- 分頁查詢的排序問題(二)排序
- mybatis多條件的模糊查詢解決方案MyBatis
- mybatis 一對一關聯MyBatis
- MyBatis 查詢資料時屬性中多對一的問題(多條資料對應一條資料)MyBatis
- 優化-mysql子查詢索引失效問題解決優化MySql索引
- mybatis多表聯合查詢的寫法MyBatis
- beego orm join 聯合查詢的問題GoORM
- Laravel 關聯查詢 ——一對一 簡單例子Laravel單例
- mybatis基礎系列(四)——關聯查詢、延遲載入、一級快取與二級快取MyBatis快取
- mybatis 對特殊字元的模糊查詢MyBatis字元
- 請教批次分頁查詢的問題
- MyBatis使用四(查詢詳解)MyBatis
- dba_free_space查詢速度慢問題解決
- 深入sql多表差異化聯合查詢的問題詳解SQL
- Hierarchical Queries 級聯查詢(樹狀結構查詢)
- Mybatis查詢MyBatis
- mybatis一對多查詢resultMap只返回了一條記錄MyBatis
- leetcode題解(查詢表問題)LeetCode