Configuration c= this.getSqlSession().getConfiguration();
ManagedTransactionFactory managedTransactionFactory = new ManagedTransactionFactory();
BatchExecutor batchExecutor=new BatchExecutor(c,managedTransactionFactory.newTransaction(this.getSqlSession().getConnection(),false));
int i = 0;
for (T entity : collection) {
batchExecutor.doUpdate(c.getMappedStatement(sql), entity);
if (i++ > 0 && i % BATCH_SIZE == 0) {
batchExecutor.doFlushStatements();
}
}
batchExecutor.doFlushStatements();
[MyBatis]获取数据库连接、批量执行SQL语句
最新推荐文章于 2023-05-13 21:00:05 发布