MyBatis-Plus分页排序问题

项目场景:

项目列表使用MyBatis-Plus分页组件,对列表进行分页、排序、分组查询。


问题描述

列表查询结果发现,每次重新调用列表接口,排序不相同。


原因分析:

最开始以为数据排序问题,把返回数组换成LinkedList后继续观察,发现不是业务代码排序导致,查看数据库查询结果,发现每次相同的SQL,相同的分页条件,数据库查询顺序都是不一样。


解决方案:

将数据库排序条件后边增加表主键,相当于组合排序,来确定数据的唯一顺序。
代码样例(prd_no_main是主键):

<select id="searchSpuGroup" resultType="com.huice.cq.stock.model.dto.SpuGroupDTO">
        select prd_no_main
        from stock_list stl
        <where>
            <include refid="stock_list_common_where"/>
        </where>
        group by prd_no_main
        <if test="param.orderColumn != null and param.orderColumn != ''">
            <if test="param.orderColumn == 3">
                order by amount desc,prd_no_main
            </if>
            <if test="param.orderColumn == 1">
                order by cus_no,prd_no_main
            </if>
            <if test="param.orderColumn == 2">
                order by cus_name,prd_no_main
            </if>
        </if>
    </select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值