<insert id="batchSaveUser"> insert into t_user (user_name,sex) values <!-- 动态SQL之foreach的用法 --> <!-- collection="users" 用于指定循环集合的名称,如果接口中并未指定参数别名,那么默认就是list item="u" 用于指定每次循环后的对象的别名 separator="," 用于指定每次循环后之间的分割符--> <foreach collection="users" item="u" separator=","> (#{u.userName},#{u.sex}) </foreach> </insert>
<delete id="batchDeleteUser"> delete from t_user where id in ( <foreach collection="ids" item="id" separator=","> #{id} </foreach> ) </delete>
3-1. 第二种批量删除的写法
3-2. open表示该语句以什么开始,close表示以什么结束
<delete id="batchDeleteUser"> delete from t_user where id in <foreach collection="ids" item="id" separator="," open="(" close=")"> #{id} </foreach> </delete>
<delete id="deleteByLogic" parameterType = "java.util.List"> delete from user where id > 2000 or id in <foreach collection="list" item="item" open="(" separator="," close=")" > #{item} </foreach> </delete>
<!--通过条件删除数据--> <delete id="batchDeleteByCondition"> delete from test where <foreach collection="list" item="item" separator=" or " index="index"> (name = #{item.name} and area_code = #{item.areaCode} and type = #{item.type}) </foreach> </delete>
<delete id="deleteBatch" parameterType="java.util.List"> delete from test where (PRSNLID, ENTID) in <foreach item="item" index="index" collection="list" separator="," open="(" close=")"> (#{item.prsnlid},#{item.entid}) </foreach> </delete>
上一篇:Cron表达范式