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

被折叠的 条评论
为什么被折叠?



