1. 当查询的参数只有一个时

findByIds(List ids)

1.a 如果参数的类型是List, 则在使用时,collection属性要必须指定为 list

5fb8baefd7080319ef02de14cf0b0a70.gif

Select                  from jria where ID in

open="(" separator="," close=")">

#{item}                

5fb8baefd7080319ef02de14cf0b0a70.gif

findByIds(Long[] ids)

1.b 如果参数的类型是Array,则在使用时,collection属性要必须指定为 array

5fb8baefd7080319ef02de14cf0b0a70.gif

                 select

          from jria where ID in

open="(" separator="," close=")">

#{item}                

5fb8baefd7080319ef02de14cf0b0a70.gif

2. 当查询的参数有多个时,例如 findByIds(String name, Long[] ids)

这种情况需要特别注意,在传参数时,一定要改用Map方式, 这样在collection属性可以指定名称

下面是一个示例

5fb8baefd7080319ef02de14cf0b0a70.gif

Map params = new HashMap(2);        params.put("name", name);         params.put("ids", ids);

mapper.findByIdsMap(params);

                 select

          from jria where ID in

open="(" separator="," close=")">

#{item}                

5fb8baefd7080319ef02de14cf0b0a70.gif

完整的示例如下:

例如有一个查询功能,Mapper接口文件定义如下方法:

List findByIds(Long... ids);

使用 in 查询的sql拼装方法如下:

5fb8baefd7080319ef02de14cf0b0a70.gif

                 select

          from jria where ID in

open="(" separator="," close=")">

#{item}                

5fb8baefd7080319ef02de14cf0b0a70.gif

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐