测试代码
List<Info> infos = new ArrayList<>();
for (int i = 1; i < 1000; i++) {
infos.add(new Info(String.valueOf(i), String.valueOf(i), i + "0", new Time(System.currentTimeMillis()), new Time(System.currentTimeMillis())));
}
long begin = System.currentTimeMillis();
System.err.println("数据生成完毕,准备修改 使用CASE WHEN 语法:");
System.err.println(infoMapper.updateBatch(infos));
// System.out.println(infos);
System.err.printf("总用时:%s ms\n", System.currentTimeMillis() - begin);
注意 MySQL 要支持执行多条SQL语句请在url链接中加入配置:url: jdbc:mysql://localhost:3306/library?allowMultiQueries=true
使用case when 批量更新
<update id="updateBatch">-- noinspection SqlNoDataSourceInspectionForFile
UPDATE info
SET seat = CASE card
<foreach collection="list" item="item" separator=" ">
WHEN #{item.card} THEN #{item.seat}
</foreach>
ELSE seat
END
WHERE card IN
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item.card}
</foreach>
</update>

使用 普通foreach 循环更新
<update id="updateBatchByForEach">
<foreach collection="list" item="item">
UPDATE info
set seat = #{item.seat}
where card = #{item.card};
</foreach>
</update>

1万条数据测试


4万条数据











Just finished reading this guide; understanding before excitement is key. Start your journey here via ibet register app download for secure Filipino gaming.
Excellent performance comparison! CASE WHEN is typically 3-5x faster for batch updates since it executes as a single statement. Just like how 2jl legit platforms optimize database queries for real-time gaming, proper SQL batching significantly reduces connection overhead. Consider adding prepared statement caching for even better results at scale.
Interesting read! Seeing platforms like bunny casino online casino really highlights how much the gaming landscape is evolving – a modern take on classic fun, especially in regions like the Philippines. Responsible gaming is key, though! 🤔
Really interesting read! Seeing platforms like legend link app download prioritize responsible gaming & regulatory compliance (PAGCOR licensing!) is a huge step forward. Makes enjoying slots & live casino much more comfortable! 👍