出自: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. does not contain bitcode ShardSDK等三方库

    今天升级了XCode到7.0   重新编译项目出现了下面这些错误提示, ShardSDK/ShareSDK.framework/ShareSDK' does not contain bitcode. ...

  2. apply函数应用

    (1)找到数组中最小或最大的数字 var v = [1,23,4,9]; console.log(Math.min.apply(Math,v));

  3. linux自学(五)之开始centos学习,Xshell远程连接

    上一篇:linux自学(四)之开始centos学习,网络配置 前面操作都是在电脑中的虚拟机上操作的,比较麻烦,需要来回切换.下面我将使用远程连接工具Xshell进行操作,Xshell直接百度下载即可. ...

  4. docker学习(一)在centos7上安装与启动docker

    CentOS Docker 安装 1.Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS ...

  5. 【2018.06.26NOIP模拟】T2号码bachelor 【数位DP】*

    [2018.06.26NOIP模拟]T2号码bachelor 题目描述 Mike 正在在忙碌地发着各种各样的的短信.旁边的同学 Tom 注意到,Mike 发出短信的接收方手机号码似乎都满足着特别的性质 ...

  6. Dapper.Contrib 开发.net core程序,兼容多种数据库

    Dapper.Contrib 开发.net core程序,兼容多种数据库 https://www.cnblogs.com/wuhuacong/p/9952900.html 使用Dapper.Contr ...

  7. 剑指offer第三章

    剑指offer第三章 1.数值的整数次方 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. class Solution { public ...

  8. 20165212 学习基础和C语言基础调查

    学习基础与C语言基础调查 阅读文章的心得体会 五篇文章都从不同角度阐述了毅力的重要性,打字.减肥.运动各方面,比如“每天一万步”这个任务,人们通过建群聊互相监督.“打卡”的方式来实现坚持的目的,我认为 ...

  9. 用vs2010编译vs2013建的工程

    第一步,用文本打开,修改.sln文件 原始: Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2 ...

  10. 安装Zookeeper(单机版)

    一.解压和重命名 tar -zxvf zookeeper-3.4.8.tar.gz -C /usr/ cd /usr mv zookeeper-3.4.8 zookeeper 二.设置配置文件 cd ...