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>
相关推荐
小九九的爸爸2 小时前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学3 小时前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田20 小时前
Pydantic校验配置文件
python
hboot20 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉