[MyBatis]获取数据库连接、批量执行SQL语句

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();

原文地址:https://www.cnblogs.com/hzcya1995/p/13318055.html