需求
foreach中要传两个参数,一个是id,一个是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>
因为我们只传了一个参数,所以这里的collection="list"会自动对应List teamList
多参数+list用map传参
传参地方:
Map params = new HashMap();
params.put("matchId", matchIdLong);
params.put("oeList", oddsEuropeList)
Mapper.java
/**
* 批量删除数据
* @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}"
就对应Map中的key为oeList的值了。