Mybatis 傳輸List的實現(xiàn)代碼
1. 當(dāng)查詢的參數(shù)只有一個時
findByIds(List<Long> ids)
1.1 如果參數(shù)的類型是List, 則在使用時,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,則在使用時,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ù)有多個時,例如 findByIds(String name, Long[] ids)
這種情況需要特別注意,在傳參數(shù)時,一定要改用Map方式, 這樣在collection屬性可以指定名稱
下面是一個示例
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的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Spring Security學(xué)習(xí)筆記(一)
這篇文章主要介紹了Spring Security的相關(guān)資料,幫助大家開始學(xué)習(xí)Spring Security框架,感興趣的朋友可以了解下2020-09-09
基于springboot+jwt實現(xiàn)刷新token過程解析
這篇文章主要介紹了基于springboot+jwt實現(xiàn)刷新token過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-03-03
java通過客戶端訪問服務(wù)器webservice的方法
這篇文章主要介紹了java通過客戶端訪問服務(wù)器webservice的方法,涉及java創(chuàng)建與調(diào)用webservice的相關(guān)技巧,需要的朋友可以參考下2016-08-08
如何使用Spring Security實現(xiàn)用戶-角色-資源的權(quán)限控制
文章介紹了如何通過SpringSecurity實現(xiàn)用戶-角色-資源的權(quán)限管理,包括基于角色的請求控制、加載用戶角色信息、角色與資源的關(guān)聯(lián)等步驟,同時,提供了一些測試場景,以驗證權(quán)限控制是否正確,感興趣的朋友跟隨小編一起看看吧2024-10-10

