利用EasyExcel导出数据库数据
一、引入EasyExcel的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.1</version>
</dependency>
二、在需要在excel中呈现的字段添加注解
public class Gps{
@ExcelProperty("id")
private Integer id;
@Schema(description = "设备名称")
@ExcelProperty("设备名称")
private String device;
@Schema(description = "上传时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
@ExcelProperty("上传时间")
private Date clientTime;
}
三、核心代码
3.1.这边做的是按照起止时间和设备名做的附带筛选功能的导出
@Override
public void getGpsExcel(GpsQueryReq req, HttpServletResponse response) {
try{
response.setContentType("application/vnd.ms-excel");