diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java b/easyexcel-core/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java index becc1748..8c3fe782 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java @@ -27,14 +27,21 @@ public class PageReadListener implements ReadListener { */ private final Consumer> consumer; + private final int pageSize; + public PageReadListener(Consumer> consumer) { + this(consumer, BATCH_COUNT); + } + + public PageReadListener(Consumer> consumer,int pageSize) { this.consumer = consumer; + this.pageSize = pageSize; } @Override public void invoke(T data, AnalysisContext context) { cachedDataList.add(data); - if (cachedDataList.size() >= BATCH_COUNT) { + if (cachedDataList.size() >= pageSize) { consumer.accept(cachedDataList); cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); } diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java index 527ca6dc..542fe463 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java @@ -52,7 +52,7 @@ public class ReadTest { for (DemoData demoData : dataList) { log.info("读取到一条数据{}", JSON.toJSONString(demoData)); } - })).sheet().doRead(); + },3)).sheet().doRead(); // 写法2: // 匿名内部类 不用额外写一个DemoDataListener