在MyBatis中,可以通过配置文件来自定义ExecutorType。ExecutorType是MyBatis中的执行器类型,包括Simple、Reuse、Batch三种类型。
要自定义ExecutorType,可以在MyBatis的配置文件(比如mybatis-config.xml)中添加如下配置:
<settings>
<setting name="defaultExecutorType" value="SIMPLE"/>
</settings>
上面的配置将ExecutorType默认设置为SIMPLE类型,可以根据需要将value的值改为其他类型,如REUSE或BATCH。
另外,也可以通过代码来动态设置ExecutorType,如下所示:
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
Configuration configuration = sqlSessionFactory.getConfiguration();
configuration.setDefaultExecutorType(ExecutorType.BATCH);
通过以上方法,就可以自定义ExecutorType来控制MyBatis的执行方式。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:pagehelper在mybatis中如何自定义分页