一、编写实体类
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZbGzglZg extends BaseEntity {
@Excel(name = "名称")
private String name;
@Excel(name = "性别",dictType = "sys_user_sex",type = Excel.Type.EXPORT)
private String sex;
@Excel(name = "图片", width = 10, height = 50, cellType = Excel.ColumnType.IMAGE)
private String image;
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date gxsj;
}
二、数据结构
{
name: "张三",
sex: "1",
image: "http://localhost:8080/profile/upload/2024/04/25/20240425153455A003.jpg",
}
三、后台导出
@PostMapping("/export")
public void export(HttpServletResponse response, UserDTO userDTO) {
List<User> dataList = userService.list(userDTO);
ExcelUtil util = new ExcelUtil(User.class);
util.exportExcel(response, dataList, "测试");
}
四、前台导出
handleExport(){
this.download('/export', {
...this.queryParams
}, `user_${new Date().getTime()}.xlsx`)
},