EasyPoi 数据脱敏

结果

规则

Controller层

java 复制代码
@CrossOrigin
    @GetMapping("/exportStudentsDesensitization")
    public void exportStudentsDesensitization(HttpServletResponse response) throws IOException {

        List<Student> studentList = studentService.list();

        List<StudentExportDesensitization> desensitizations = studentList.stream().map(e -> {

            StudentExportDesensitization studentExportDesensitization = new StudentExportDesensitization();
            BeanUtil.copyProperties(e, studentExportDesensitization, false);
            return studentExportDesensitization;

        }).collect(Collectors.toList());

        // 设置响应输出的头类型
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 设计导出文件的名称,尽量不要中文
        String fileName = new String("导出.xls".getBytes(), "ISO-8859-1");
        response.setHeader("Content-Disposition","attachment;filename="+fileName);
        //输出流。
        ServletOutputStream out = response.getOutputStream();
        // 创建参数对象(用来设定excel得sheet的内容等信息)
        ExportParams params = new ExportParams() ; //sheet
        // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
        params.setSheetName("导出");
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("2412312", "测试", "测试"), StudentExportDesensitization.class, desensitizations);
        workbook.write(out);


    }

导出Entity

java 复制代码
@Data
public class StudentExportDesensitization implements java.io.Serializable{


    /**
     * 学生姓名
     */
    @Excel(name = "学生姓名", height = 20, width = 30,desensitizationRule = "1,6")
    private String        name;
    /**
     * 学生性别
     */
    @Excel(name = "学生性别", replace = { "男_1", "女_0" }, suffix = "生")
    private int           sex;

    @Excel(name = "出生日期", databaseFormat = "yyyy-MM-dd HH:mm:ss", format = "yyyy-MM-dd",  width = 20)
    private LocalDateTime birthDay;

    @Excel(name = "进校日期", databaseFormat = "yyyy-MM-dd HH:mm:ss", format = "yyyy-MM-dd")
    private LocalDateTime registrationDate;

    @Excel(name = "身份证", desensitizationRule = "6_4")
    private String card;
    @Excel(name = "手机号", desensitizationRule = "3_4")
    private String phone;
    @Excel(name = "邮箱", desensitizationRule = "3~@")
    private String email;

}

数据库

导入pom

java 复制代码
<dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-spring-boot-starter</artifactId>
    <version>4.4.0</version>
</dependency>
相关推荐
电商API_180079052479 分钟前
API分享:获取淘宝商品价格|详情|主图|sku信息
开发语言·c++·人工智能·数据分析
一定要AK13 分钟前
java基础
java·开发语言·笔记
splage20 分钟前
Java进阶之泛型
java·开发语言
xiaohe0722 分钟前
JAVA系统中Spring Boot 应用程序的配置文件:application.yml
java·开发语言·spring boot
羊小蜜.23 分钟前
C++17: map & multimap—— 键值映射容器
开发语言·c++·stl
Eternity_GQM23 分钟前
【CMake入门】
java·开发语言
王小义笔记28 分钟前
大模型微调步骤与精髓总结
python·大模型·llm
酉鬼女又兒1 小时前
零基础快速入门前端蓝桥杯Web备考:BOM与定时器核心知识点详解(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·javascript·职场和发展·蓝桥杯
望眼欲穿的程序猿1 小时前
MacOS自定义安装Rust
开发语言·macos·rust