接口
/** * 批量添加员工 * @param emps * @return */ boolean insertEmp(@Param("emps") List<Emp> emps);
sql
<insert id="insertEmp"> insert into emp values <foreach collection="emps" item="emp" separator=","> (null,#{emp.empName},#{emp.age},#{emp.gender},null) </foreach> </insert>
/** * 通过名字批量删除数据 * @param * @return */ boolean deleteEmp(@Param("empName") String[] empName);
<delete id="deleteEmp"> DELETE FROM emp WHERE emp_name in ( <foreach collection="empName" item="emp" separator=","> #{emp} </foreach> ) </delete>
List<Emp>selectUserEmp(Emp emp);
<select id="selectUserEmp" resultMap="empResultMap1"> select * from emp <where> <if test="empName != null and empName !=''"> emp_name = #{empName} </if> <if test="age != null and age !=''"> and age = #{age} </if> <if test="gender != null and gender !=''"> and gender = #{gender} </if> </where> </select>