Mybatis如何根据List批量查询List结果
时间:2022-08-21 09:59:53|栏目:JAVA代码|点击: 次
根据List批量查询List结果
mapper接口
/** * 根据剧典id list查询剧典 */ public List<Drama> selectByIds(@Param("dramaIds")List<Long> dramaIds);
mapper.xml文件
<!-- 根据剧典id list查询剧典 --> <select id="selectByIds" resultMap="DramaImageResultMap"> select * from drama where drama_id in <foreach collection="dramaIds" item="dramaId" open="(" close=")" separator=","> #{dramaId} </foreach> </select>
数组参数
//接口方法 ArrayList<User> selectByIds(Integer [] ids); //xml映射文件 <select id="selectByIds" resultMap="BaseResultMap"> select * from user where id in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </select>
List参数
//接口方法 ArrayList<User> selectByIds(List<Integer> ids); //xml映射文件 <select id="selectByIds" 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>
根据多条件List查询
mapper文件
<select id="selectWhere" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from table <where> table.a = a and table.b in <foreach collection="list" item="item" index="index" open="(" separator="," close=")"> '${item}' </foreach> </where> </select>
DAO片段
List<T> selectWhere(@Param("list")List<String> list ,@Param("a") String a);
栏 目:JAVA代码
下一篇:Springboot之restTemplate的配置及使用方式
本文标题:Mybatis如何根据List批量查询List结果
本文地址:http://www.codeinn.net/misctech/211457.html