请问各位大佬一个问题,我在使用 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
我在 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 就报错呢?求解答,谢谢。