zoukankan      html  css  js  c++  java
  • 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>



  • 相关阅读:
    linux异步信号handle浅析
    数据库的基本操作增删改查
    POJ1789Truck History最小生成树两种做法(Kruskal+Prim)模板题
    POJ1113Wall求凸包周长
    POJ3565AntsKM变形
    HDU2150Pipe判断线段是否相交
    POJ1815Friendship最大流最小割点+拆点+枚举
    HDU3081 Marriage Match II 最大匹配+并查集+匈牙利算法
    POJ3348Cows求凸包面积
    HDU3277Marriage Match III并查集+二分+最大流
  • 原文地址:https://www.cnblogs.com/ding08/p/11686309.html
Copyright © 2011-2022 走看看