mybatis oracle in查询,mybatis中使用in查询时的注意事项
1.当查询的参数只有一个时findByIds(Listids)1.a如果参数的类型是List,则在使用时,collection属性要必须指定为list SelectfromjriawhereIDinopen="("separator=","close=")">#{item} findByIds(Long...
1. 当查询的参数只有一个时
findByIds(List ids)
1.a 如果参数的类型是List, 则在使用时,collection属性要必须指定为 list

Select from jria where ID in
open="(" separator="," close=")">
#{item}

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

select
from jria where ID in
open="(" separator="," close=")">
#{item}

2. 当查询的参数有多个时,例如 findByIds(String name, Long[] ids)
这种情况需要特别注意,在传参数时,一定要改用Map方式, 这样在collection属性可以指定名称
下面是一个示例

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}

完整的示例如下:
例如有一个查询功能,Mapper接口文件定义如下方法:
List findByIds(Long... ids);
使用 in 查询的sql拼装方法如下:

select
from jria where ID in
open="(" separator="," close=")">
#{item}

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



所有评论(0)