之前都是遍历一个集合然后一条一条的执行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" />但是配了以后发现没有什么用,只需要在遍历时加上代码中的加红的部分即可。
特别注意:我不是多写了一个逗号;