Mybatis batch update problem: continuous breakthrough in solving problems

Remember a batch update bug fix process for mybatis

Version one

<update id="updateIsDelStatus" parameterType="java.util.List">
  <foreach collection="list" item="item" index="index" separator=";" close="" open="">
    update inp_record set IR_IsDel = -1
    where IR_ID = #{item,jdbcType=INTEGER}
  </foreach>
</update>

An error was reported during the test of version 1, because in the joint debugging with the front-end, considering that the size of the word into the parameter list is not very large (use in is recommended to control size <= 10), temporarily use version 2 for emergency repair

Version two

<update id="updateIsDelStatus" parameterType="java.util.List">
    update inp_record set IR_IsDel = -1
    where IR_ID in
  <foreach collection="list" item="item" index="index" separator="," close=")" open="(">
    #{item,jdbcType=INTEGER}
  </foreach>
</update>

The problem has been basically solved, but I feel that the silly handling of things can not solve the problem, so I conducted an in-depth study and found that Mybatis only executes one SQL by default, so the version one is written to execute multiple SQLs, so it will be the first An error is reported when the sentence is sql.

Solution:

Add in the jdbcurl path: allowMultiQueries=true

However, it is not recommended to use multiple SQLs to execute at the same time. Try to use a single SQL to implement business logic according to actual business scenarios.

 

Guess you like

Origin blog.csdn.net/A___B___C/article/details/95452299