Mybatis如何根據(jù)List批量查詢List結(jié)果
更新時間:2022年03月11日 10:02:27 作者:安,財
這篇文章主要介紹了Mybatis如何根據(jù)List批量查詢List結(jié)果,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
根據(jù)List批量查詢List結(jié)果
mapper接口
/**
?* 根據(jù)劇典id list查詢劇典
?*/
public List<Drama> selectByIds(@Param("dramaIds")List<Long> dramaIds);mapper.xml文件
<!-- 根據(jù)劇典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>數(shù)組參數(shù)
//接口方法
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參數(shù)
//接口方法
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>?根據(jù)多條件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);以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
spring cloud中微服務(wù)之間的調(diào)用以及eureka的自我保護(hù)機制詳解
這篇文章主要介紹了spring cloud中微服務(wù)之間的調(diào)用以及eureka的自我保護(hù)機制詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07
Spring Boot 中PageHelper 插件使用配置思路詳解
這篇文章主要介紹了Spring Boot 中PageHelper 插件使用配置及實現(xiàn)思路,通過引入myabtis和pagehelper依賴,在yml中配置mybatis掃描和實體類,具體實現(xiàn)方法跟隨小編一起看看吧2021-08-08
Java攔截過濾器模式 (Intercepting Filter )實現(xiàn)方法
攔截過濾器模式(Intercepting Filter Pattern)用于對應(yīng)用程序的請求或響應(yīng)做一些預(yù)處理/后處理,本文通過實例代碼介紹Java攔截過濾器模式 (Intercepting Filter )的相關(guān)知識,感興趣的朋友跟隨小編一起看看吧2024-03-03
mybatis中方法返回泛型與resultType不一致的解決
這篇文章主要介紹了mybatis中方法返回泛型與resultType不一致的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07
Java?SpringBoot整合shiro-spring-boot-starterqi項目報錯解決
這篇文章主要介紹了Java?SpringBoot整合shiro-spring-boot-starterqi項目報錯解決,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考一下2022-08-08

