MyBatis-Plus依赖版本
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.4.1</version>
</dependency>
Postgresql依赖版本
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
</dependency>
配置(重点)
mybatis-plus:
configuration:
default-fetch-size: 1000
代码
public void selectData() {
try {
// **重点**
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, true);
dbMapper.selectList(null, resultContext -> {
try {
// 数据处理
} catch (Exception e) {
log.error("流式处理失败", e);
}
});
sqlSession.commit();
sqlSession.close();
} catch (Exception e) {
log.error("数据异步查询失败", e);
}
}