Mybatis进行批量更新操作

<update id="updateBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update deviceparameterdetail
            <set>
                <if test="item.DeviceParameteValue != null">
                    DeviceParameteValue = #{item.DeviceParameteValue,jdbcType=VARCHAR},
                </if>
                <if test="item.UploadFlag != null">
                    UploadFlag = #{item.UploadFlag,jdbcType=BIT},
                </if>
                <if test="item.UpdateTime != null">
                    UpdateTime = #{item.UpdateTime,jdbcType=TIMESTAMP},
                </if>
                <if test="item.ProcotolID != null">
                    ProcotolID = #{item.ProcotolID,jdbcType=INTEGER},
                </if>
            </set>
            where
                DeviceID = #{item.DeviceID,jdbcType=VARCHAR} and
                DeviceParameterCode = #{item.DeviceParameterCode,jdbcType=VARCHAR}
        </foreach>
    </update>

需要注意的是:必须在配置连接数据库url后面带一个参数 &allowMultiQueries=true,表示允许批量操作,例
url: jdbc:mysql://127.0.0.1:3306/cw_vehicle?useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8mb4_general_ci&serverTimezone=GMT%2B8&allowMultiQueries=true


版权声明:本文为HeliosJ原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。