From ac1128eddbc38702db107f2ea2a3f3b5ad855350 Mon Sep 17 00:00:00 2001 From: ls9527 <364173778@qq.com> Date: Sun, 8 Jan 2023 18:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E8=AF=BB=E5=8F=96=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E5=99=A8=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=9D=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/excel/read/listener/PageReadListener.java | 9 ++++++++- .../com/alibaba/easyexcel/test/demo/read/ReadTest.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) 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