delete from t_user where id in ids;ids为id的数组 sql1
delete from t_user where id = ? or id =? or id =?; ids为数组 sql2
1.以arg0或者array作为键,将数组封装成一个map,按键取值
我们也可以:
1.传入一个自定义map
2.@param注解
delete from t_user where id in ids
<delete id="deleteMany"> delete from t_user where id in <foreach collection="ids" item="id" separator="," open="(" close=")"> #{id} </foreach> </delete>
<foreach collection="ids" item="id" separator="," open="(" close=")">
collection="ids" 接受List集合(mybatis默认的处理方式就按arg0、array接受,@param处理方式就按注解value值接受,自定义map方式就按键名接受,都不加#{}或者${})
item="id" List集合种每个元素都以id为键,因为是循环,所以一次只将一个元素的键设置为id
separator="," 每次循环结果之间添加的分割符,分隔符号前后自带一个空格
open="(" close=")" 循环开始前添加,循环结束时添加
delete from t_user where id = ? or id =? or id =?
<delete id="deleteMany"> delete from t_user where <foreach collection="ids" item="id" separator="or"> 分割符换成了or,循环前后也不需要添加任何字符串 id = #{id} </foreach> </delete>