Mybatis批量update修改实例

UserMapper.xml 配置:

<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代码调用:

userMapper.batchUpdateByCnd(list);

猜你喜欢

转载自blog.csdn.net/zixiao217/article/details/80437603