温馨提示×

如何在MyBatis中设置ExecutorType

小樊
103
2024-08-07 20:41:19
栏目: 编程语言

在 MyBatis 中设置 ExecutorType 有两种方法:

  1. 在配置文件中设置: 在 MyBatis 的配置文件 mybatis-config.xml 中添加如下配置:
<settings>
    <setting name="executorType" value="REUSE"/>
</settings>

其中,executorType 的值可以是 SIMPLE、REUSE 或 BATCH,分别代表不同的 ExecutorType。默认值是 SIMPLE。

  1. 在 SqlSessionFactory 中设置: 在代码中创建 SqlSessionFactory 时,可以使用 SqlSessionFactoryBuilder 的 build 方法来设置 ExecutorType:
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, "REUSE");

以上代码中的第二个参数就是指定的 ExecutorType,可以是 SIMPLE、REUSE 或 BATCH。

0