Mybatis批量update修改实例

2023-05-05 17:30:59 浏览数 (1)

UserMapper.xml 配置:

代码语言:javascript复制
<sql id="condition4Update">
        <where>
            <if test="orgNo != null" >
                 AND org_no = #{orgNo,jdbcType=VARCHAR}
              </if>
              <if test="uid != null" >
                 AND uid = #{uid,jdbcType=VARCHAR}
              </if>
              <if test="productNo != null" >
                 AND product_no = #{productNo,jdbcType=VARCHAR}
              </if>
        </where>
    </sql>
<!-- 批量修改 -->
    <update id="batchUpdateByCnd" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";"> 
            update 
                user
            <set>
                  proc_status = #{item.procStatus},
                  fail_code = #{item.failCode},
                  fail_reason = #{item.failReason},
                  modify_date = #{item.modifyDate},
                  version = version   1
            </set>
            <include refid="condition4Update" />
         </foreach>
    </update>   

JAVA代码调用:

代码语言:javascript复制
userMapper.batchUpdateByCnd(list);

0 人点赞