这次要做一个springboot+easyexcel的整合,因为要处理大量数据,选择了easyexcel,进行了简单的整合。
1、首先是导入POM依赖
<!-- 阿里开源框架EasyExcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.10</version>
</dependency>
<!--fast-json 解析json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
2、实体类
这里的@ExcelIgnore,@ExcelProperty是easyexcel的常用注解,第一个是导入导出时忽略该字段,第二个里的index是排序。
package com.hc.store.model;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 商品实体类
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Product {
/**
* 测试EasyExcel
* 实现excel表格导入数据库与数据库导出到excel表格
*/
@ExcelIgnore
private Integer id;
@ExcelProperty(value = "分类id",index = 0)
private Integer category_id;
@ExcelProperty(value = "商品类型",index = 1)
private String item_type;
@ExcelProperty(value = "商品标题",index = 2)
private String title;
@ExcelProperty(value = "商品卖点",index = 3)
private String sell_point;
@ExcelProperty(value = "单价",index = 4)
private Long price;
@ExcelProperty(value = "库存数量",index = 5)
private Integer num;
@ExcelProperty(value = "图片路径",index = 6)
private String image;
@ExcelProperty(value = "商品状态",index = 7)
private Integer status;
@