Mybatis batch update error reporting
- 2020-06-01 09:56:09
- OfStack
Now I would like to introduce the problem of batch update error reporting of mybatis.
allowMultiQueries=true
Later, it was found that the jdbc link did not add parameters to allow batch update operation, so it will not report badsql, mysql version of mybatis batch update operation as follows
<update id="updateOrderOverdueStatus" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update t_am_bystages_order
<set>
overdue_status=#{item.overdueStatus}
</set>
where order_id=#{item.orderId}
</foreach>
</update>
Let's take a look at how Mybatis updates data in bulk
The first way
<update id="updateBatch" parameterType="Map">
update aa set
a=#{fptm},
b=#{csoftrain}
where c in
<foreach collection="cs" index="index" item="item" pen="("separator=","close=")">
#{item}
</foreach>
</update>
But the field values modified this way are all 1.
The second way
Modify the database connection configuration
:&allowMultiQueries=true
Such as: jdbc: MySQL: / / 192.168.1.236:3306 / test & # 63; useUnicode = true & amp;characterEncoding=UTF-8 & allowMultiQueries=true
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>
This way, you can execute more than one SQL statement at a time
Reference:
mybatis method for performing batch update of batch update (oracle,mysql)