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>
相关推荐
Hello World呀6 小时前
Java实现手机号和身份证号脱敏工具类
java·开发语言
BoBoZz196 小时前
MarchingCubes 网格数据体素化并提取等值面
python·vtk·图形渲染·图形处理
曹牧6 小时前
Java:serialVersionUID
java·开发语言
ekprada7 小时前
DAY36 复习日
开发语言·python·机器学习
qq_256247057 小时前
Rust 模块化单体架构:告别全局 Migrations,实现真正的模块自治
开发语言·架构·rust
爱笑的眼睛117 小时前
强化学习组件:超越Hello World的架构级思考与实践
java·人工智能·python·ai
历程里程碑7 小时前
C++ 6 :string类:高效处理字符串的秘密
c语言·开发语言·数据结构·c++·笔记·算法·排序算法
Boxsc_midnight7 小时前
【规范驱动的开发方式】之【spec-kit】 的安装入门指南
人工智能·python·深度学习·软件工程·设计规范
武帝为此7 小时前
【字典树 C++ 实现】
开发语言·c++