mybatis中批量增、删、改的SQL语句

来源:互联网 发布:mysql skip limit 编辑:程序博客网 时间:2024/06/05 09:24

1.批量增

  <insert id="insertBatch" parameterType="java.util.List">    insert into SYS_DEPT (     DEPT_ID, ORG_ID, DEPT_NAME, LEADER, IS_USED, REMARK,       ENTRY_PROGRAM,ENTRY_USER, MODIFY_DATE, MODIFY_PROGRAM, MODIFY_USER      )     <foreach collection="list" item="dept" index="index" open="(" separator="union" close=")">     select      #{dept.deptId,jdbcType=VARCHAR}, #{dept.orgId,jdbcType=VARCHAR}, #{dept.deptName,jdbcType=VARCHAR},          #{dept.leader,jdbcType=VARCHAR}, #{dept.isUsed,jdbcType=DECIMAL}, #{dept.remark,jdbcType=VARCHAR},          #{dept.entryProgram,jdbcType=VARCHAR}, #{dept.entryUser,jdbcType=VARCHAR},          #{dept.modifyDate,jdbcType=DATE}, #{dept.modifyProgram,jdbcType=VARCHAR}, #{dept.modifyUser,jdbcType=VARCHAR}         from dual    </foreach>  </insert>

2.批量删

  <delete id="deleteBatch" parameterType="java.util.List">    delete from SYS_DEPT    where DEPT_ID IN    <foreach collection="list" item="sd" index="index" open="(" separator="," close=")">        #{sd.deptId,jdbcType=VARCHAR}    </foreach>  </delete>

3.批量改

  <update id="updateBatch" parameterType ="java.util.List">    <foreach collection="list" item="user" index="index" open="begin" separator=";" close=";end;">      update SYS_USER       set IS_USED = #{user.isUsed}      where USER_ID = #{user.userId}    </foreach>  </update>
原创粉丝点击