allowMultiQueries=true&rewriteBatchedStatements=true

本文介绍MyBatis配置项allowMultiQueries与rewriteBatchedStatements的作用。rewriteBatchedStatements能够提高执行效率,通过合并多次executeBatch请求为单一请求并发送至数据库。特别地,对于INSERT语句,该选项还能将其合并为单条INSERT语句。文中还提供了如何检查MySQL通用查询日志的方法以及使用MyBatis-Plus的saveBatch方法实现相同效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

allowMultiQueries允许mybatis一个标签里写多条语句提交

rewriteBatchedStatements能提高效率,无视executeBatch意思是会等executeBatch执行了多次后,将这多次请求合并为一个请求发送给数据库,而如果是insert语句,还会将这些insert合并为一条inset,即insert into table() values();insert into table() values();insert into table() values();这种变成insert into table() values(),(),()

mybatis的日志可能还是显示insert into table() values();insert into table() values();insert into table() values();
但是可以查看mysql的通用查询日志是insert into table() values(),(),()格式
打开mysql通用查询日志的方法

show variables like 'general%';
SET GLOBAL general_log=1; # 开启查询日志

在这里插入图片描述
要想达到insert into table() values(),(),()的效果可以使用mybatis-plus的saveBatch方法,并且设置连接rewriteBatchedStatements=true

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值