一、前言
前面介绍了裸露JDBC 方式使用流式编程,下面介绍下MYbatis中两种使用流式查询方法
二、Mybaits中MyBatisCursorItemReader的使用
2.1 配置
MyBatisCursorItemReader的注入
value="com.taobao.accs.mass.petadata.dal.sqlmap.AccsDeviceInfoDAOMapper.selectByExampleForPetaData" />
其中queryId为mapper文件中接口名称。
Mapper.xml设置

image.png
其中fetchSize=”-2147483648″,Integer.MIN_VALUE=-2147483648
2.2 使用
static void testCursor1() throws UnexpectedInputException, ParseException, Exception{
try {
Map param = new HashMap();
AccsDeviceInfoDAOExample accsDeviceInfoDAOExample = new AccsDeviceInfoDAOExample();
accsDeviceInfoDAOExample.createCriteria().andAppKeyEqualTo("12345").andAppVersionEqualTo("5.7.2.4.5")
.andPackageNameEqualTo("com.test.zlx");
param.put("oredCriteria", accsDeviceInfoDAOExample.getOredCriteria());
// 设置参数
myMyBatisCursorItemReader.setParameterValues(param);
// 创建游标
myMyBatisCursorItemReader.open(new ExecutionContext());
//使用游标迭代获取每个记录
Long count = 0L;
AccsDeviceInfoDAO accsDeviceInfoDAO;
while ((accsDeviceInfoDAO = myMyBatisCursorItemReader.read