mybatis?foreach傳兩個(gè)參數(shù)批量刪除
需求
foreach中要傳兩個(gè)參數(shù),一個(gè)是id,一個(gè)是list。怎么傳呢?
單list的情況
Mapper.java
/** * 批量刪除 * @param teamList * @return */ public int batchDeleteBizTeam(List<BizTeam> teamList);
Mapper.xml
<delete id="batchDeleteBizTeam"> delete from biz_team where id in <foreach item="item" collection="list" separator="," open="(" close=")" index=""> #{item.id} </foreach> </delete>
因?yàn)槲覀冎粋髁艘粋€(gè)參數(shù),所以這里的collection="list"會(huì)自動(dòng)對(duì)應(yīng)List teamList
多參數(shù)+list用map傳參
傳參地方:
Map params = new HashMap(); params.put("matchId", matchIdLong); params.put("oeList", oddsEuropeList)
Mapper.java
/** * 批量刪除數(shù)據(jù) * @param params * @return */ public int batchDeleteOddsEurope(Map params);
Mapper.xml
<delete id="batchDeleteOddsEurope"> delete from biz_odds_europe where match_id=#{matchId} and company_id in <foreach item="item" collection="oeList" separator="," open="(" close=")" index=""> #{item.companyId} </foreach> </delete>
這里的 collection="#{oeList}"
就對(duì)應(yīng)Map中的key為oeList的值了。
參考資料
https://www.cnblogs.com/fnlingnzb-learner/p/10566452.html
到此這篇關(guān)于mybatis foreach 批量刪除 傳兩個(gè)參數(shù)的文章就介紹到這了,更多相關(guān)mybatis foreach 批量刪除內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
IDEA報(bào)java:?java.lang.OutOfMemoryError:?Java?heap?space錯(cuò)誤
這篇文章主要給大家介紹了關(guān)于IDEA報(bào)java:?java.lang.OutOfMemoryError:?Java?heap?space錯(cuò)誤的解決辦法,文中將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01springboot代碼,注解配置獲取yml,properties文件的map即鍵值對(duì)
這篇文章主要介紹了springboot代碼,注解配置獲取yml,properties文件的map即鍵值對(duì),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02高效數(shù)據(jù)傳輸?shù)拿孛芪淦鱌rotobuf的使用教程
Protobuf(Protocol?Buffers)是由?Google?開發(fā)的一種輕量級(jí)、高效的數(shù)據(jù)交換格式,它被用于結(jié)構(gòu)化數(shù)據(jù)的序列化、反序列化和傳輸,本文主要介紹了它的具體使用方法,需要的可以參考一下2023-05-05關(guān)于SpringMVC中控制器如何處理文件上傳的問題
這篇文章主要介紹了關(guān)于SpringMVC中控制器如何處理文件上傳的問題,在 Web 應(yīng)用程序中,文件上傳是一個(gè)常見的需求,例如用戶上傳頭像、上傳文檔等,本文將介紹 Spring MVC 中的控制器如何處理文件上傳,并提供示例代碼,需要的朋友可以參考下2023-07-07Java Set接口及常用實(shí)現(xiàn)類總結(jié)
Collection的另一個(gè)子接口就是Set,他并沒有我們List常用,并且自身也沒有一些額外的方法,全是繼承自Collection中的,因此我們還是簡(jiǎn)單總結(jié)一下,包括他的常用實(shí)現(xiàn)類HashSet、LinkedHashSet、TreeSet的總結(jié)2023-01-01Spring?Security放行的接口Knife4j靜態(tài)資源的問題小結(jié)
這篇文章主要介紹了Spring?Security使用Knife4j靜態(tài)資源的問題小結(jié),項(xiàng)目中使用?Spring?Security?做身份認(rèn)證和授權(quán),使用?Knife4j?做接口調(diào)試,需要?Spring?Security?放行的接口記錄在?RequestMatcherConstant?類中,感興趣的朋友跟隨小編一起看看吧2024-02-02