一、根据List集合查询数据
1. xml代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17// controller接口调用 List<Integer> idList = new ArrayList<>(); idList.add(1); idList.add(2); List<TUser> list1 = ttUserMapper.findList1(idList); // 接口 List<TUser> findList1(@Param("idList")List<Integer> idList); // xml <select id="findList1" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from t_user where id in <foreach collection="idList" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </select>
或者接口中不写注解@Param("idList"),xml里的collection="list" 这样就行
二、根据数组查询数据
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18// controller调用接口 Integer[] ids = new Integer[3]; ids[0] = 1; ids[1] = 2; ids[2] = 3; List<TUser> list2 = ttUserMapper.findList2(ids); // 接口 List<TUser> findList2(@Param("idList")Integer[] idList); // xml <select id="findList2" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from t_user where id in <foreach collection="idList" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </select>
或者接口中不写注解@Param("idList"),xml里的collection="array" 这样就行
最后
以上就是幸福火车最近收集整理的关于Mybatis 根据集合、数组查询数据的几种方法的全部内容,更多相关Mybatis内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复