SpringBoot 导出excel,浏览器下载

1、添加Dependency


    cn.afterturn
    easypoi-base
    3.1.0


    org.apache.poi
    poi
    3.16

2、导出excel

List list =  查询的内容;

Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("列表", "列表"),
        VoExcel.class, dataList);
ExeclUtil.downLoadExcel("taskList.xls", response, workbook);

3、定义导出实体类

package com.admin.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import java.util.Date;

@ExcelTarget("voExcel")
public class VoExcel{
    private String id;
    private String productId;

    @Excel(name="添加时间",orderNum="1",exportFormat="yyyy-MM-dd hh:mm:ss",width = 18)
    private Date createDateTime;

    @Excel(name="网址",orderNum="2",width = 18)
    private String url;
    getter setter省略

}

 

4、浏览器访问接口:http://127.0.0.1:8080/admin/exportExcel,如图

SpringBoot 导出excel,浏览器下载_第1张图片

5、举例:

(1)前端:

导出

(2)controller

(3)service

SpringBoot 导出excel,浏览器下载_第2张图片

 

 
注:service也可以换另一种写法,调用工具类ExcelUtil(ExcelUtil查看本人另一篇博客)

SpringBoot 导出excel,浏览器下载_第3张图片

你可能感兴趣的:(工具类,导出excel,easypoi导出excel,springboot,easypoi导出,springboot,excel浏览器下载)