Mybatis如何根据List批量查询List结果
更新时间:2022年03月11日 10:02:27 作者:安,财
这篇文章主要介绍了Mybatis如何根据List批量查询List结果,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
根据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);以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
spring cloud中微服务之间的调用以及eureka的自我保护机制详解
这篇文章主要介绍了spring cloud中微服务之间的调用以及eureka的自我保护机制详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-07-07
Spring Boot 中PageHelper 插件使用配置思路详解
这篇文章主要介绍了Spring Boot 中PageHelper 插件使用配置及实现思路,通过引入myabtis和pagehelper依赖,在yml中配置mybatis扫描和实体类,具体实现方法跟随小编一起看看吧2021-08-08
Java拦截过滤器模式 (Intercepting Filter )实现方法
拦截过滤器模式(Intercepting Filter Pattern)用于对应用程序的请求或响应做一些预处理/后处理,本文通过实例代码介绍Java拦截过滤器模式 (Intercepting Filter )的相关知识,感兴趣的朋友跟随小编一起看看吧2024-03-03
mybatis中方法返回泛型与resultType不一致的解决
这篇文章主要介绍了mybatis中方法返回泛型与resultType不一致的解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-07-07
Java SpringBoot整合shiro-spring-boot-starterqi项目报错解决
这篇文章主要介绍了Java SpringBoot整合shiro-spring-boot-starterqi项目报错解决,文章围绕主题展开详细的内容介绍,具有一定的参考一下2022-08-08


最新评论