Mybatis实现批量增加、批量删除和批量修改
1、批量增加
1 <!--批量增加--> 2 <insert id="saveSignData" parameterType="java.util.List"> 3 insert 4 into 5 sign 6 (user_id, sign_time, sign_status, late_time) 7 values 8 <foreach collection="list" item="item" index="index" separator=","> 9 (#{item.userId,jdbcType=INTEGER},#{item.signTime,jdbcType=VARCHAR}, 10 #{item.signStatus,jdbcType=VARCHAR}, #{item.lateTime,jdbcType=VARCHAR}) 11 </foreach> 12 </insert>
2、批量删除
1 <!--批量删除--> 2 <delete id="deletes" parameterType="java.util.List"> 3 delete from team where id in 4 <foreach collection="list" item="ids" open="(" separator="," close=")"> 5 #{ids,jdbcType=INTEGER} 6 </foreach> 7 </delete>
3、批量修改
1 <update id="updateStudents"> 2 update 3 user 4 set 5 team = 6 <foreach collection="list" item="item" index="index" separator=" " open="case" close="end"> 7 when id = #{item.id} then '' 8 </foreach> 9 where 10 id 11 in 12 <foreach collection="list" item="item" index="index" separator="," open="(" close=")"> 13 #{item.id} 14 </foreach> 15 </update>