mybatis foreach传两个参数批量删除
需求
foreach中要传两个参数,一个是id,一个是list。怎么传呢?
单list的情况
Mapper.java
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>
因为我们只传了一个参数,所以这里的collection="list"会自动对应List teamList
多参数+list用map传参
传参地方:
Map params = new HashMap();
params.put("matchId", matchIdLong);
params.put("oeList", oddsEuropeList)
Mapper.java
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}"
就对应Map中的key为oeList的值了。
参考资料
https://www.cnblogs.com/fnlingnzb-learner/p/10566452.html
到此这篇关于mybatis foreach 批量删除 传两个参数的文章就介绍到这了,更多相关mybatis foreach 批量删除内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
相关文章