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)文章
SpringBoot實現(xiàn)WEB的常用功能案例詳解
這篇文章主要介紹了SpringBoot實現(xiàn)WEB的常用功能,本文將對Spring Boot實現(xiàn)Web開發(fā)中涉及的三大組件Servlet、Filter、Listener以及文件上傳下載功能以及打包部署進行實現(xiàn),需要的朋友可以參考下2022-04-04Java實現(xiàn)雪花算法的原理和實戰(zhàn)教程
這篇文章主要介紹了Java實現(xiàn)雪花算法的原理和實戰(zhàn)教程,本文通過語言表述和代碼的實現(xiàn)講解了該項算法,,需要的朋友可以參考下2021-06-06Java java.lang.InstantiationException異常案例詳解
這篇文章主要介紹了Java java.lang.InstantiationException異常案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08Java遞歸算法經(jīng)典實例(經(jīng)典兔子問題)
本文主要對經(jīng)典的兔子案例分析,來進一步更好的理解和學(xué)習(xí)java遞歸算法,具有很好的參考價值,需要的朋友一起來看下吧2016-12-12詳解Intellij IDEA中.properties文件中文顯示亂碼問題的解決
這篇文章主要介紹了詳解Intellij IDEA中.properties文件中文顯示亂碼問題的解決,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11Java?EasyExcel導(dǎo)出合并單元格的示例詳解
EasyExcel是阿里巴巴開源的一個excel處理框架,以使用簡單、節(jié)省內(nèi)存著稱,這篇文章主要為大家介紹了如何利用EasyExcel導(dǎo)出合并單元格,需要的可以參考下2023-09-09