读取代码
// 前端传过来的文件
MultipartFile file;
InputStream inputStream = file.getInputStream();
// 读取excel数据,边读取边处理;
EasyExcel.read(inputStream, ImportSkuIdList.class, new SkuIdExceListener(sendCouponCusRecordService)).sheet().doRead();
解析对象
public class ImportSkuIdList{
@ExcelProperty(index = 0)
/** 商品编号*/
private Long skuId;
// 省略get set
....
}
Listener
public class SkuIdExceListener extends AnalysisEventListener {
private static final Logger LOGGER = LoggerFactory.getLogger(SkuIdExceListener.class);
// spring的方式需要通过构造函数传进来
private SendCouponCusRecordService sendCouponCusRecordService;
/**
* 每隔100条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
*/
private static final int BATCH_COUNT = 100;
private