java easyexcel 导出 精简版

导出

    @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);

    }

/**
 * @description: 文件工具类
 * @author: hanxs - 2022/07/15
 */
public class FileUtil {
    /**
     * 导出表格数据
     *
     * @param response
     * @param dateList
     * @param fileName
     * @param <T>
     * @throws Exception
     */
    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");
            // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
            fileName = URLEncoder.encode(fileName + MyDateUtil.getSdfTimes(), "UTF-8").replaceAll("\\+", "%20");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            //同步
            //  intoEnvSettingsService.controlDoorSystem(3);

            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>

/**
 * @desc  实体
 * @author chenfeixiang
 * @since 2021-10-27
 */
@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)
    //@ExcelIgnore
    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;



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值