bokiBiabu 2022-05-27 14:25 采纳率: 40%
浏览 260
已结题

mybatis-plus 不用QueryWrapper怎么实现自定义sql的in查询

mybatis-plus 不用QueryWrapper怎么实现自定义sql in查询

@Select("SELECT s.id submit_id,s.create_time,s.submit_content,s.rule_id,s.is_overtime,s.staff_id,t.staff_name,t.staff_avatar " +
        "FROM application.report_submit s LEFT JOIN application.enterprise_staff t on t.staff_id = s.staff_id " +
        "where s.id in (${coll})")
List<Map<String,Object>> testGetList(@Param(Constants.COLLECTION) List<Integer> ids);

这个生成的sql 后面 是这样where s.id in ([20, 21, 22])
或者

@Select("SELECT s.id submit_id,s.create_time,s.submit_content,s.rule_id,s.is_overtime,s.staff_id,t.staff_name,t.staff_avatar " +
        "FROM application.report_submit s LEFT JOIN application.enterprise_staff t on t.staff_id = s.staff_id " +
        "where s.id in " +
       "<foreach collection=#{ids} item=id index=index" +
        " open=\"(\" close=\")\" separator=\",\">" +
        "   #{id}" +
        "</foreach>")
List<Map<String,Object>> testGetList(@Param("ids") List<Integer> ids);

这个就报错 id找不到 #{id}

因为wrapper好像只能传一个 所以 有些条件得这样写 或者说 可不可以传多个wrapper进查询
@Param(Constants.WRAPPER) Wrapper wrapper

  • 写回答

6条回答 默认 最新

  • 皮蛋不吃粥 2022-05-27 14:35
    关注

    querywrapper 直接in

    
            new QueryWrapper<>()
                    .in()
    

    img

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月19日
  • 创建了问题 5月27日

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程