|
|
@ -2,6 +2,7 @@ package com.alibaba.easyexcel.test.temp; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -9,6 +10,7 @@ import org.slf4j.LoggerFactory; |
|
|
|
import com.alibaba.easyexcel.test.demo.read.DemoDataListener; |
|
|
|
import com.alibaba.easyexcel.test.demo.read.DemoDataListener; |
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
|
|
|
|
|
import com.alibaba.excel.metadata.CellData; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -16,16 +18,16 @@ import com.alibaba.fastjson.JSON; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Jiaju Zhuang |
|
|
|
* @author Jiaju Zhuang |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LockDataListener extends AnalysisEventListener<LockData> { |
|
|
|
public class LockDataListener extends AnalysisEventListener<Map<Integer, CellData>> { |
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); |
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 |
|
|
|
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static final int BATCH_COUNT = 5; |
|
|
|
private static final int BATCH_COUNT = 5; |
|
|
|
List<LockData> list = new ArrayList<LockData>(); |
|
|
|
List<Map<Integer, CellData>> list = new ArrayList<Map<Integer, CellData>>(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void invoke(LockData data, AnalysisContext context) { |
|
|
|
public void invoke(Map<Integer, CellData> data, AnalysisContext context) { |
|
|
|
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); |
|
|
|
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); |
|
|
|
list.add(data); |
|
|
|
list.add(data); |
|
|
|
if (list.size() >= BATCH_COUNT) { |
|
|
|
if (list.size() >= BATCH_COUNT) { |
|
|
|