springboot + easyexcel 简单整合

本文介绍了如何在SpringBoot项目中整合EasyExcel处理大量数据,通过添加POM依赖、创建实体类和ExcelController,实现了数据的导出和上传功能。详细步骤包括设置注解、编写监听器和业务实现,以及SQL语句的操作。
摘要由CSDN通过智能技术生成

这次要做一个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;
    @
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值