Mybatis 傳輸List的實(shí)現(xiàn)代碼
1. 當(dāng)查詢的參數(shù)只有一個(gè)時(shí)
findByIds(List<Long> ids)
1.1 如果參數(shù)的類型是List, 則在使用時(shí),collection屬性要必須指定為 list
Xml代碼
<select id="findByIdsMap" 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>
<select id="findByIdsMap" 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>
findByIds(Long[] ids)
1.2 如果參數(shù)的類型是Array,則在使用時(shí),collection屬性要必須指定為 array
Xml代碼
<select id="findByIdsMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tabs where ID in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="findByIdsMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tabs where ID in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
#{item}
</foreach>
</select>
2. 當(dāng)查詢的參數(shù)有多個(gè)時(shí),例如 findByIds(String name, Long[] ids)
這種情況需要特別注意,在傳參數(shù)時(shí),一定要改用Map方式, 這樣在collection屬性可以指定名稱
下面是一個(gè)示例
Map<String, Object> params = new HashMap<String, Object>(2);
params.put("name", name);
params.put("ids", ids);
mapper.findByIdsMap(params);
Xml代碼
<select id="findByIdsMap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tabs where ID in
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
#{item}
</foreach>
</select>
總結(jié)
以上所述是小編給大家介紹的Mybtis 傳輸List的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Springboot的自動(dòng)配置是什么及注意事項(xiàng)
SpringBoot的自動(dòng)配置(Auto-configuration)是指框架根據(jù)項(xiàng)目的依賴和應(yīng)用程序的環(huán)境自動(dòng)配置Spring應(yīng)用上下文中的Bean和組件,目的是簡化開發(fā)者的配置工作,本文介紹Springboot的自動(dòng)配置是什么及注意事項(xiàng),感興趣的朋友一起看看吧2025-03-03
Spring Security學(xué)習(xí)筆記(一)
這篇文章主要介紹了Spring Security的相關(guān)資料,幫助大家開始學(xué)習(xí)Spring Security框架,感興趣的朋友可以了解下2020-09-09
基于springboot+jwt實(shí)現(xiàn)刷新token過程解析
這篇文章主要介紹了基于springboot+jwt實(shí)現(xiàn)刷新token過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
java通過客戶端訪問服務(wù)器webservice的方法
這篇文章主要介紹了java通過客戶端訪問服務(wù)器webservice的方法,涉及java創(chuàng)建與調(diào)用webservice的相關(guān)技巧,需要的朋友可以參考下2016-08-08
SpringBoot實(shí)現(xiàn)api加密的示例代碼
在項(xiàng)目中,為了保證數(shù)據(jù)的安全,我們常常會(huì)對(duì)傳遞的數(shù)據(jù)進(jìn)行加密。本文主要介紹了SpringBoot實(shí)現(xiàn)api加密的示例代碼,感興趣的小伙伴們可以參考一下2021-07-07
java基于odbc連接oracle的實(shí)現(xiàn)方法
這篇文章主要介紹了java基于odbc連接oracle的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了連接操作的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-09-09
如何使用Spring Security實(shí)現(xiàn)用戶-角色-資源的權(quán)限控制
文章介紹了如何通過SpringSecurity實(shí)現(xiàn)用戶-角色-資源的權(quán)限管理,包括基于角色的請(qǐng)求控制、加載用戶角色信息、角色與資源的關(guān)聯(lián)等步驟,同時(shí),提供了一些測(cè)試場景,以驗(yàn)證權(quán)限控制是否正確,感興趣的朋友跟隨小編一起看看吧2024-10-10

