出自: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. Ubuntu12.04中安装Oracle JDK和NetBeans的方法

    1.到官网下载jdk-7u51-linux-i586.tar.gz安装包 2.创建jvm文件夹 $sudo mkdir /usr/lib/jvm 3.将安装包解压到上述文件夹下 $-linux-i58 ...

  2. Unity的 NavMeshObstacle 的使用详解

            这个组件放在场景中的导航网格上,可以阻挡NavMeshAgent的移动.以Unity4.3.4为例.         NavMeshObstacle 分为两种模式,一种是普通模式,通过 ...

  3. skywalking探针tomcat8.0.28报错解决

    在部署skywalking agent的时候遇到一个异常 环境如下: tomcat8.0.28 catalina.out 日志报如下错误 30-Apr-2019 10:25:57.664 INFO [ ...

  4. JSON 总结

          <!--Json格式配置映射 直接能访问JSON文本数据--> <system.webServer> <staticContent> <mimeM ...

  5. iOS设备是否越狱的判断代码

    苹果是非常看重产品的安全性的,所以给用户设计了一套复杂的安全机制.这让喜爱自由,崇尚一切开放的程序员们极度不爽,于是越狱就成了苹果和黑客们反复斗法的场所.总体来说,越狱可以让我们随意安装.共享应用,但 ...

  6. python(十三):网络编程之socket与socketserver

    socket是操作系统中I/O系统延伸部分,支持TCP和UDP等网络通信协议,它使计算机之间(或其本身)的进程通信称为可能.socket中的socket()函数.recv()函数和send()函数,相 ...

  7. js 时间date格式化

    js中没有类似java中的DateFormat类来处理日期格式化,可以自己写一个: var newDate=new Date(); var year=newDate.getFullYear(); va ...

  8. flask第十四篇——重定向

    我们都知道京东的url是www.jd.com,但是当你输入www.jingdong.com时候,你会发现地址自动跳转到了www.jd.com,这种技术手段就叫做重定向. 重定向分为永久重定向和临时重定 ...

  9. vault key 管理工具

    Vault is a tool for securely accessing secrets. A secret is anything that you want to tightly contro ...

  10. 笔记:使用 stylus stylus-loader

    笔记:使用 stylus stylus-loader 安装 stylus Stylus-loader cnpm i stylus stylus-loader --save 配置 webpack.con ...