题目
MyBatis 都有哪些 Executor 执行器
答案

1)`BaseExecutor`:实现了 Executor 的全部方法,包括对缓存,事务,连接提供了一系列的**模板方法**,**这些模板方法中留出来了四个抽象的方法等待子类去实现**
```java
protected abstract int doUpdate(MappedStatement ms, Object parameter)
throws SQLException;
protected abstract List<BatchResult> doFlushStatements(boolean isRollback)
throws SQLException;
protected abstract <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSQL boundSQL)
throws SQLException;
protected abstract <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSQL boundSQL)
throws SQLException;
```
`BaseExecutor` 包含三个直接子类:
- `SimpleExecutor` :每执行一次 update 或 select,**就开启一个 Statement 对象,用完立刻关闭 Statement 对象**(默认的 Executor)。
- `ReuseExecutor` :执行 update 或 select,以 SQL 作为 key 查找 Statement 对象,存在就使用,不存在就创建,用完后,不关闭 Statement 对象,而是放置于 Map<String, Statement>内,供下一次使用。简言之,就是**重复使用 Statement 对象**
- `BatchExecutor` :执行 update(没有 select,JDBC 批处理不支持 select),将所有 SQL 都添加到批处理中(addBatch()),等待统一执行(executeBatch()),它**缓存了多个 Statement 对象,每个 Statement 对象都是 addBatch()完毕后,等待逐一执行 executeBatch()批处理**。与 JDBC 批处理相同
2)`CachingExecutor`:主要和 MyBatis 二级缓存有关,详细可见 [itmtx 482 题: 介绍 MyBatis 的一级缓存和二级缓存](https://itmtx.cn/question/482)
