出自:http://blog.csdn.net/u013628152/article/details/51184641

1. findByIds(List ids)

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

<select id="findByIdsMap" resultMap="BaseResultMap">
Select
<include refid="Base_Column_List" />
from jria where ID in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>

2:findByIds(Long[] ids)

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

<select id="findByIdsMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tabs where ID in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
#{item}
</foreach>
</select>

3. findByIds(String name, Long[] ids)

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

 Map<String, Object> params = new HashMap<String, Object>(2);
params.put("name", name);
params.put("ids", ids);
mapper.findByIdsMap(params);
<select id="findByIdsMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tabs where
name = #{name}
and ID in
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
#{item}
</foreach>
</select>
 

mybatis 传入集合参数遍历 查询总结的更多相关文章

  1. MyBatis传入集合 list 数组 map参数的写法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有item,index,collection,open,separator,close.ite ...

  2. mybatis传入map参数,map中包含list(输入参数)

    1.xml中配置: <!-- 根据条件查询满足条件的ID集合开始 --> <select id="getQuestionsIdsForExamPaper" res ...

  3. 解决使用Mybatis 传入多参数使用map封装遇到的 “坑”问题

    好久没来写些东西了,今天 我分享一下自己遇到的一个“小 坑”,这也许对您来说不是个问题,但是我还是希望对没有遇到过这类问题的朋友给个小小的帮助吧 是这样的,需求:需要实现根据多条件 且分页展示数据 1 ...

  4. 查询的model里面 一般都要有一个要返回的model做属性 ;查询前要传入得参数,查询后返回的参数 都要集合在一个model中

    查询的model里面 一般都要有一个要返回的model做属性

  5. mybatis关联集合List&分布查询传递多列值

    场景:查询部门的同时,要求查询此部门下的所有用户. 部门(Department) private Integer id; private String departmentName; private ...

  6. mybatis传入map参数parameterType

    基本数据类型:包含int,String,Date等.基本数据类型作为传参,只能传入一个.通过#{参数名} 即可获取传入的值 复杂数据类型:包含JAVA实体类.Map.通过#{属性名}或#{map的Ke ...

  7. MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.

    在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...

  8. mybatis 根据多个id查询数据 foreach标签

    //根据设备多个id获取设备信息 public List<Devices> getDevicesAll(@Param("devicesIds") String[] de ...

  9. MyBatis参数传入集合之foreach用法

    传入集合list // 账户类型包括门店和分公司 List<Object> scopeList = new ArrayList<Object>(); scopeList.add ...

随机推荐

  1. selenium-java,UI自动化截图方法

    截图方法: import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; impor ...

  2. CF1109A Sasha and a Bit of Relax

    CF1109A Sasha and a Bit of Relax 用 \(xorsum[l,r]\) 表示 \(a[l] \oplus a[l+1] \oplus a[l+2]... a[r-1] \ ...

  3. python selenium 开发环境配置

    selenium是一个web测试应用框架也可以拿来做爬虫. 1.安装selenium模块 pip install -U selenium 2.安装selenium模块后需要有相应的浏览器驱动 A.使用 ...

  4. simulink生成hdl的几个理解

    1,simulink生成hdl的话需要用支持的模块,否则不能生成,支持的模块组成一个库,这个库需要自己生成,用hdllib命令生成,官方原话: The hdllib function creates ...

  5. ballerina 学习五 使用composer管理ballerina 项目

    1. 启动 composer 备注: 因为这个命名和php的一个包管理工具重名了,所以可能需要使用决定路径 比如我的mac系统使用:Library/Ballerina/ballerina-0.970. ...

  6. CentOS下编译安装LNMP环境

    一.卸载系统预安装的LAMP软件 rpm -qa|grep httpd rpm -e httpd httpd-tools rpm -qa|grep mysql rpm -e mysql mysql-l ...

  7. 笔记:服务器压缩方案 来源于 Accept-Encoding: gzip, deflate 问题

    笔记:服务器压缩方案 来源于 Accept-Encoding: gzip, deflate 问题 事情起因:odoo demo 没有启动web 压缩 目前流行的 web 压缩技术 gzip br 支持 ...

  8. Android 从上层到底层-----jni层

    CPU:RK3288 系统:Android 5.1 功能:上层 app 控制 led 亮灭 开发板:Firefly RK3288 led_jni.h path:hardware/rockchip/fi ...

  9. Python中的url编码问题

    >>> import urllib >>> a = "PythonTab中文网" >>> a 'PythonTab\xe4\x ...

  10. Windows10+CUDA8.0+VS2015+CUDNN5下配置caffe

    [转]https://blog.csdn.net/zhj_matlab/article/details/69943869