导出
@GetMapping(value = "/exportList")
@ApiOperation(value = "导出所有人员指纹人脸信息")
public void exportList(HttpServletResponse response) throws Exception {
List<IntoUserExtend> list = intoUserExtendService.list();
String fileName = URLEncoder.encode("人脸指纹列表" + MyDateUtil.getSdfTimes(), "UTF-8").replaceAll("\\+", "%20");
FileUtil.exportList2xlsx(response, list, fileName);
}
public class FileUtil {
public static <T> void exportList2xlsx(HttpServletResponse response, List<T> dateList, String fileName) throws Exception {
if (CollectionUtils.isNotEmpty(dateList)) {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
fileName = URLEncoder.encode(fileName + MyDateUtil.getSdfTimes(), "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), dateList.get(0).getClass())
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("模板").doWrite(dateList);
}
}
}
环境准备
<!-- easy excel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value="IntoUserExtend对象", description="")
public class IntoUserExtend implements Serializable {
@TableId
@ApiModelProperty(value = "唯一标识")
@ExcelProperty(value = "ID")
private String userId;
@ApiModelProperty(value = "门禁的工号")
@ExcelProperty(value = "门禁的工号")
private String jobNumber;
@ApiModelProperty(value = "卡号")
@ExcelProperty(value = "卡号")
private String icCard;
@ApiModelProperty(value = "手机号")
@ExcelProperty(value = "手机号")
@ExcelIgnore
private String phone;
@ApiModelProperty(value = "人脸识别图片的base64")
@ExcelProperty(value = "人脸识别图片的base64",converter = MyStringImageConverter.class)
private String facePicBase64;
@ApiModelProperty(value = "指纹")
@ExcelProperty(value = "指纹")
private String fingerprint;
@ApiModelProperty(value = "姓名")
@ExcelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "角色 1:库房管理员,0-普通用户")
@ExcelIgnore
private UserRoleEnum role;
@ApiModelProperty(value = "性别")
@ExcelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "密码")
@ExcelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "my_size")
@ExcelProperty(value = "图像大小")
private String mySize;
@ApiModelProperty(value = "my_length")
@ExcelProperty(value = "图像长度")
private String myLength;
@ApiModelProperty(value = "my_offset")
@ExcelProperty(value = "图像偏移量")
private String myOffset;
@ApiModelProperty(value = "avatar")
@ExcelProperty(value = "图像相对地址")
private String avatar;
@ApiModelProperty(value = "group_id")
@ExcelProperty(value = "组id")
@ExcelIgnore
private String groupId;
}