xml中批量新增數據或者批量修改數據


批量提交多條語句需要在 mysql 的連接里面開啟 allowMultiQueries=true
如:url: jdbc:mysql://127.0.0.1:3306/ku?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

<insert id="batchInsert" parameterType="com.Entity">
    insert into pos_parameter ( store_id, pos_id,
    parameter_id, parameter_name, parameter_value,
    parameter_desc, parameter_type, is_show,
    is_modify, create_user_id, memo,
    created_time, updated_time)
    values
  <foreach collection="list"  item="param" index="index" separator=",">
    ( #{param.storeId,jdbcType=VARCHAR}, #{param.posId,jdbcType=VARCHAR},
    #{param.parameterId,jdbcType=VARCHAR}, #{param.parameterName,jdbcType=VARCHAR}, #{param.parameterValue,jdbcType=VARCHAR},
    #{param.parameterDesc,jdbcType=VARCHAR}, #{param.parameterType,jdbcType=INTEGER}, #{param.isShow,jdbcType=CHAR},
    #{param.isModify,jdbcType=CHAR}, #{param.createUserId,jdbcType=VARCHAR}, #{param.memo,jdbcType=VARCHAR},
    #{param.createdTime,jdbcType=TIMESTAMP}, #{param.updatedTime,jdbcType=TIMESTAMP})
  </foreach>
</insert>

 

<update id="batchUpdate" parameterType="com.Entity">
  <foreach item="param" collection="list" separator=";" index="index">
    update pos_parameter
    <set>
      <if test="param.storeId != null">
        store_id = #{param.storeId,jdbcType=VARCHAR},
      </if>
      <if test="param.posId != null">
        pos_id = #{param.posId,jdbcType=VARCHAR},
      </if>
      <if test="param.parameterId != null">
        parameter_id = #{param.parameterId,jdbcType=VARCHAR},
      </if>
      <if test="param.parameterName != null">
        parameter_name = #{param.parameterName,jdbcType=VARCHAR},
      </if>
      <if test="param.parameterValue != null">
        parameter_value = #{param.parameterValue,jdbcType=VARCHAR},
      </if>
      <if test="param.parameterDesc != null">
        parameter_desc = #{param.parameterDesc,jdbcType=VARCHAR},
      </if>
      <if test="param.parameterType != null">
        parameter_type = #{param.parameterType,jdbcType=INTEGER},
      </if>
      <if test="param.isShow != null">
        is_show = #{param.isShow,jdbcType=CHAR},
      </if>
      <if test="param.isModify != null">
        is_modify = #{param.isModify,jdbcType=CHAR},
      </if>
      <if test="param.createUserId != null">
        create_user_id = #{param.createUserId,jdbcType=VARCHAR},
      </if>
      <if test="param.memo != null">
        memo = #{param.memo,jdbcType=VARCHAR},
      </if>
      <if test="param.createdTime != null">
        created_time = #{param.createdTime,jdbcType=TIMESTAMP},
      </if>
      <if test="param.updatedTime != null">
        updated_time = #{param.updatedTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{param.id,jdbcType=BIGINT}
  </foreach>
</update>

 





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM