package com.atguigu.mybatis.mapper; import com.atguigu.mybatis.pojo.Emp; import org.apache.ibatis.annotations.Param; import java.util.List; /** * Date:2021/11/30 * Author:ybc * Description: */ public interface DynamicSQLMapper { /** * 通过数组实现批量删除 */ int deleteMoreByArray(@Param("eids") Integer[] eids); /** * 通过list集合实现批量添加 */ int insertMoreByList(@Param("emps") List<Emp> emps); }
<!--int insertMoreByList(@Param("emps") List<Emp> emps);--> <insert id="insertMoreByList"> insert into t_emp values <foreach collection="emps" item="emp" separator=","> (null,#{emp.empName},#{emp.age},#{emp.sex},#{emp.email},null) </foreach> </insert> <!--int deleteMoreByArray(@Param("eids") Integer[] eids);--> <delete id="deleteMoreByArray"> delete from t_emp where <foreach collection="eids" item="eid" separator="or"> eid = #{eid} </foreach> <!-- delete from t_emp where eid in <foreach collection="eids" item="eid" separator="," open="(" close=")"> #{eid} </foreach> --> </delete>
若未指定别名,传入的参数为list的时候 collection="list"
若未指定别名,传入的参数为array的时候 collection="array"