温馨提示×

如何在MyBatis中设置ExecutorType

小樊
134
2024-08-07 20:41:19
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在 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。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:MyBatis中ExecutorType有哪些类型

0