oracle+mybatis 实现批量更新

       之前都是遍历一个集合然后一条一条的执行sql语句,这样在数据量小的时候没有什么问题,但是当数据量大的时候访问数据库的次数就太多了,难免会对性能造成一定的影响。所以选择了批量更新;

<foreach collection="list" item="temp" index="index" open="begin" close=";end;" separator=";">
            update prpPolicyToDisaster
                <set>
                    <if test="temp.groupNo  != null">groupNo = #{temp.groupNo ,jdbcType=VARCHAR}, </if>
                    <if test="temp.groupNoRegCount  != null">groupNoRegCount = #{temp.groupNoRegCount ,jdbcType=INTEGER}, </if>
                    <if test="temp.isRegit  != null">isRegit = #{temp.isRegit ,jdbcType=VARCHAR}, </if>
                    <if test="temp.isMainFlag  != null">isMainFlag = #{temp.isMainFlag ,jdbcType=VARCHAR}, </if>
                    <if test="temp.policyType  != null">policyType = #{temp.policyType ,jdbcType=VARCHAR}, </if>
                    <if test="temp.registBatch != null"> registBatch=#{temp.registBatch,jdbcType=VARCHAR},</if>
                    <if test="temp.addressCode != null"> addressCode=#{temp.addressCode,jdbcType=VARCHAR},</if>
                    <if test="temp.insuredCode != null"> insuredCode=#{temp.insuredCode,jdbcType=VARCHAR},</if>
                    <if test="temp.updateBy  != null">updateBy = #{temp.updateBy ,jdbcType=VARCHAR}, </if>
                    <if test="temp.updateTime  != null">updateTime = #{temp.updateTime ,jdbcType=DATE}, </if>
                    <if test="temp.createBy  != null">createBy = #{temp.createBy ,jdbcType=VARCHAR}, </if>
                    <if test="temp.createTime  != null">createTime = #{temp.createTime ,jdbcType=DATE}</if>
                </set>
                <where>
                    <if test="temp.disasterCode !=null">
                        disasterCode = #{temp.disasterCode,jdbcType=VARCHAR}  
                    </if>
                    <if test="temp.groupNo !=null">
                        and groupNo = #{temp.groupNo,jdbcType=VARCHAR}
                    </if>
                    <if test="temp.serialNo !=null">
                        and serialNo = #{temp.serialNo,jdbcType=INTEGER}
                    </if>
                </where>
        </foreach>

 刚才是在网上查都说要配  allowMultiQueries=true ;或者<setting name="defaultExecutorType" value="BATCH" />但是配了以后发现没有什么用,只需要在遍历时加上代码中的加红的部分即可。

特别注意:我不是多写了一个逗号

 

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值