mybatis 传入集合参数遍历 查询总结
出自: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 传入集合参数遍历 查询总结的更多相关文章
- MyBatis传入集合 list 数组 map参数的写法
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有item,index,collection,open,separator,close.ite ...
- mybatis传入map参数,map中包含list(输入参数)
1.xml中配置: <!-- 根据条件查询满足条件的ID集合开始 --> <select id="getQuestionsIdsForExamPaper" res ...
- 解决使用Mybatis 传入多参数使用map封装遇到的 “坑”问题
好久没来写些东西了,今天 我分享一下自己遇到的一个“小 坑”,这也许对您来说不是个问题,但是我还是希望对没有遇到过这类问题的朋友给个小小的帮助吧 是这样的,需求:需要实现根据多条件 且分页展示数据 1 ...
- 查询的model里面 一般都要有一个要返回的model做属性 ;查询前要传入得参数,查询后返回的参数 都要集合在一个model中
查询的model里面 一般都要有一个要返回的model做属性
- mybatis关联集合List&分布查询传递多列值
场景:查询部门的同时,要求查询此部门下的所有用户. 部门(Department) private Integer id; private String departmentName; private ...
- mybatis传入map参数parameterType
基本数据类型:包含int,String,Date等.基本数据类型作为传参,只能传入一个.通过#{参数名} 即可获取传入的值 复杂数据类型:包含JAVA实体类.Map.通过#{属性名}或#{map的Ke ...
- 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 ...
- mybatis 根据多个id查询数据 foreach标签
//根据设备多个id获取设备信息 public List<Devices> getDevicesAll(@Param("devicesIds") String[] de ...
- MyBatis参数传入集合之foreach用法
传入集合list // 账户类型包括门店和分公司 List<Object> scopeList = new ArrayList<Object>(); scopeList.add ...
随机推荐
- 编程技巧:使用异或操作符(XOR)交换两数值
异或(exclusive OR)作为4种逻辑操作符之一,相对其他3种(OR/AND/NOT)来说,出场的次数非常少,是因为在日常开发中能用到它的场景本来就不多.对笔者来说,目前接触到场景只有交换两个数 ...
- 20179223《Linux内核原理与分析》第七周学习笔记
视频知识学习 1.fork()函数被调用一次,但返回两次: 2.Linux通过复制父进程来创建一个子进程,通过调用fork来实现: 3.Linux会为每个子进程动态的分配一个task_struct结构 ...
- 《selenium2 python 自动化测试实战》(15)——调用js控制滚动条等操作
看代码: # coding=utf-8 from time import sleepfrom selenium import webdriver driver = webdriver.Firefox( ...
- ballerina 学习十一 Packages
ballerina 的包还是比较简单的,实际上就是对于源码文件集合的管理,同时我们可以添加别名,同时可以进行 其他包的引用 import 简单例子 代码 import ballerina/math; ...
- Openfire源码使用Install4j打包
https://www.ej-technologies.com/download/install4j/files 下载并安装install4jhttps://www.ej-technologies.c ...
- warning: backslash and newline separated by space [enabled by default]
警告:反斜杠和换行符之间多了空格. 这种问题出现在宏定义 #define,并且有多行,每行之间要用 “\” 连接起来. 解决办法:删除 “\” 后面的空格,直接紧跟回车.
- Oracle导出导入表空间创建
//备份数据库前的sqlplus命令创建数据库dmp存入目录 sqlplus /nolog conn /as sysdba SQL> create or replace directory ex ...
- laravel Auth token创建于使用
token 的创建和使用, https://laravelacademy.org/post/3640.html 用户表密码字段验证修改,不只是password https://www.jianshu. ...
- (转)Linq DataTable的修改和查询
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Msys2+mingw-w64 编译VS2013使用的ffmpeg静态库注意事项
1.环境准备 第一步:从http://sourceforge.net/projects/msys2/下载msys2的安装程序安装msys2; 第二步:通过msys2的包管理工具pacman安装ming ...