一、批量操作
// 1、批量新增
// 返回自增id(useGeneratedKeys="true" keyProperty="id")
<insert id="saveBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
insert into sys_user
(
user_name,
sex
)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.userName},
#{item.sex}
)
</foreach>
</insert>
<insert id="updateBatch" parameterType="java.util.List">
<foreach collection="list" item="item" separator=";">
update sys_user
<set>
<if test="item.userName!=null and item.userName!=''">
user_name = #{item.userName},
</if>
<if test="item.sex!=null">
user_age = #{item.sex},
</if>
</set>
where user_id = #{item.userId}
</foreach>
</insert >
// 2、批量修改
<update id="updateBatch" parameterType="java.util.List">
<foreach collection="list" item="item" separator=";">
update sys_user
<set>
<if test="item.userName!=null and item.userName!=''">
user_name = #{item.userName},
</if>
<if test="item.sex!=null">
sex= #{item.sex},
</if>
</set>
where user_id = #{item.userId}
</foreach>
</update>
//3、批量删除
<delete id="deleteByLogic" parameterType = "java.util.List">
delete from sys_user where id in
<foreach collection="list" item="item" open="(" separator="," close=")" >
#{item}
</foreach>
</delete>