V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
kyoma
V2EX  ›  问与答

关于 mybatisPlus 和传入动态参数排序的问题

  •  
  •   kyoma · 2022-04-21 12:06:18 +08:00 · 670 次点击
    这是一个创建于 749 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问各位大佬一个问题,我在使用 mybatisplus 时候遇到一个场景: 首先 有用户、商户、运营者这三个角色,用户申请成为运营者之后,就会在 shop_operator 表中建立一条关联关系,在界面 [申请成为运营者] 当中,需要查询出所有的店铺信息,然后将具有关联关系的店铺置顶 我是这么做的,首先查出登陆人的 id ,然后查关联关系,找出与我有关联的商铺 id ,然后把商铺 id 列表传入到查询 sql 中进行 order by desc 排序,但是此时会报错 Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql : \n SELECT COUNT(1) FROM op_shop_info osi WHERE osi.shop_status = '1' 我在 Mapper 中的接口: IPage queryShopListAndApplySts(Page page, @Param("shopName") String shopName, @Param("shopIds") List shopIds,@Param("userId") Integer userId);

    我在 xml 中写的 sql: select osi.shop_id, osi.shop_name, oso.apply_status, oso.ct_time as apply_time from op_shop_info osi left join op_shop_operator oso on osi.shop_id = oso.shop_id and oso.user_id = #{userId} <where> osi.shop_status = '1' <if test="shopName != null and shopName != ''"> and osi.shop_name like concat('%', #{shopName}, '%') </if> </where> <if test="shopIds != null and shopIds.size() != 0"> order by osi.shop_id in <foreach collection="shopIds" item="shopId" index="index" open="(" separator="," close=")"> #{shopId} </foreach> desc </if>

    -- 最后是以查询 List ,然后对 List 手动分页暂时解决了。 还是对于原来写法这个报错很费解,那个 SELECT COUNT(*)是用来查询总条数的吧,为什么加上 order by 就报错呢?求解答,谢谢。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   6187 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:10 · PVG 14:10 · LAX 23:10 · JFK 02:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.