<!-- 批量新增第一种方式 --> <insertid="batchInsert"parameterType="java.util.List"> INSERT INTO STUDENT(ID,NAME) <foreachcollection="list"item="student"separator="UNION ALL"> ( SELECT #{student.id}, #{student.name} FROM dual ) </foreach> </insert>
1 2 3 4 5 6 7 8 9
<!-- 批量插入第二种方式 --> <insertid="batchInsert"parameterType="java.util.List"> INSERT ALL <foreachcollection="list"item="student"> into STUDENT(ID,NAME) VALUES(#{student.id},#{student.name}) </foreach> SELECT 1 FROM DUAL </insert>
1 2 3 4 5 6 7 8 9 10 11 12
<!-- 批量更新 --> <updateid="batchUpdate"parameterType="java.util.List"> <foreachcollection="list"item="student"index="index"open="begin"close=";end;"separator=";"> UPDATE STUDENT <set> <iftest="student.name != null and student.name != ''"> NAME = #{student.name} </if> </set> WHERE ID = #{student.id} </foreach> </update>
1 2 3 4 5 6 7 8 9 10
<!-- 批量删除 --> <deleteid="batchDeleteByIds"parameterType="java.lang.String"> DELETE FROM STUDENT WHERE ID IN <foreachcollection="array"item="id"opean="("separator=","close=")"> #{id} </foreach> </delete>