相关依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
实体类
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("sys_log")
public class LogVO implements Serializable {
@TableId(value ="id" ,type = IdType.AUTO)
@Excel(name = "id",orderNum = "1",type = 10)
private Long id;
@Excel(name = "用户id",orderNum = "2")
private Long userId;
@Excel(name = "用户名称",orderNum = "3",width = 20)
private String username;
@Excel(name = "用户操作",orderNum = "4")
private String operation;
@Excel(name = "响应时间",orderNum = "5")
private int time;
@Excel(name = "请求方法",orderNum = "6",width = 60)
private String method;
@Excel(name = "请求参数",orderNum = "7",width = 20)
private String params;
@Excel(name = "ip地址",orderNum = "8",width = 20)
private String ip;
@Excel(name = "创建时间",orderNum = "9",width = 20,exportFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
private Date gmtCreate;
@Excel(name = "操作描述",orderNum = "10",width = 20)
private String description;
## 处理方法
@ApiOperation(value = "获取日志列表", notes = "")
@GetMapping("/exlDownload")
public void exlDownload(@RequestParam Map<String, String> params, HttpServletResponse response) throws UnsupportedEncodingException {
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String fileName = "日志记录" + date + ".xls";
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.addHeader("Content-Disposition",
"attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
PageUtils pageUtils = sysLogService.list(params);
try {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), LogVO.class, pageUtils.getRows());
OutputStream out = response.getOutputStream();
workbook.write(out);
out.close();
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}