在工作的时候发现了Mybatisplus自带的更新操作在数据量大的表中时非常慢,可以使用多线程来完成,但是实现不了多线程的事务回滚
因为是sqlServer数据库,没有mysql的&rewriteBatchedStatements=true的属性,executeBatch()的批处理也没用
需要自己手写:
<update id="updateBatchByIdMy" parameterType="java.util.List" keyProperty="id">
update CFG_CON_SUBJECTPARAM_INFO
<trim prefix="set" suffixOverrides=",">
<trim prefix="CONID = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.conid}
</foreach>
</trim>
<trim prefix="SUBJECTID = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.subjectid}
</foreach>
</trim>
<trim prefix="OUTTEMP = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.outtemp}
</foreach>
</trim>
<trim prefix="SUPTEMP = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.suptemp}
</foreach>
</trim>
<trim prefix="RETTEMP = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.rettemp}
</foreach>
</trim>
<trim prefix="AVGTEMP = case id" suffix="end,">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.avgtemp}
</foreach>
</trim>
<trim prefix="DIFFTEMP = case id" suffix="end">
<foreach collection="list" item="item" index="index">
when #{item.id} then #{item.difftemp}
</foreach>
</trim>
where id in
<trim>
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{item.id}
</foreach>
</trim>
</trim>