mybatis-plus 使用rewriteBatchedStatements提供批量保存性能
只需要在yml配置文件后面添加rewriteBatchedStatements=true;
例子如下:
url: jdbc:mysql://ip:3306/库名?useUnicode=true&characterEncoding=utf-8&useSSL=false&nullCatalogMeansCurrent=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
这样在批量保存的时候就会相当于手动拼写sql一样: insert into xxx values (a),(b),(c)...
那为什么默认不给这个参数设置为 true 呢?
原来是这样的:
如果批量语句中的某些语句失败,则默认重写会导致所有语句都失败。
批量语句的某些语句参数不一样,则默认重写会使得查询缓存未命中。
浙公网安备 33010602011771号