出自: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. 使用django搭建博客并部署

    2017/8/31 18:27:59 为了以后参考的方便,在这里总结一下django搭建博客网站的主要步骤.以下大部分的内容,参考自Django中文文档 - 看云. 需要强调的是,这里使用的djang ...

  2. kettle连接oracle出现Error connecting to database: (using class oracle.jdbc.driver.OracleDriver)

    jdbc驱动,下载jdbc14.jar文件放入   pdi-ce-5.3.0.0-213\data-integration\libswt\win64里 之后重启kettle即可 jdbc14.jar文 ...

  3. 一个关于PCA的疑问

    我们知道PCA干的事情是把n维的样本投影到k维,同时丢失的信息能够达到最少. 为什么说principal component是covariance matrix的特征值中最大的前k个对应的特征向量上的 ...

  4. 使用jenkins持续集成自动化测试

    本文采用Springboot开发一个简易的添加个人资料和查询个人资料接口,并采用testng进行测试,使用jenkis进行持续继承,allure输出测试报告. 个人资料查询接口开发(集成H2数据库) ...

  5. matlab图像处理注意溢出!先要im2double!

    imagedata_comb=imagedata_ebic*addnumber_ebic+imagedata_sem*addnumber_sem; %注意溢出啊!!!uint8最大值是255,也就是说 ...

  6. Jsp邮件找回密码全攻略

    [来源网络  http://www.2cto.com/kf/201502/376374.html] 一般大型网站我们登录的时候,密码忘了都有个功能可以找回密码. 细数下大致的方法: 1.直接把密码发送 ...

  7. JSP学习(五)JSP标签

    JSP标签 jsp的常用标签有: <jsp:include>标签 <jsp:forward>标签 <jsp:param>标签 <jsp:include> ...

  8. 服务器上通过FTP共享文件夹

    近日,公司某服务器共同操作的人员增多,而我只需访问及替换某些文件,故想到共享文件夹. 在IIS中建立ftp站点,添加虚拟目录(可多个,对应不同文件夹),设置允许访问的用户(添加用户,见在IIS上搭建F ...

  9. Nomad 了解

    Introduction to Nomad Welcome to the intro guide to Nomad! This guide is the best place to start wit ...

  10. xunsearch安装及环境检测(一)

    1.运行执行下载解压安装包wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2解压到指定目录 tar -xjf xu ...