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>
相关推荐
sycmancia13 分钟前
Qt——编辑交互功能的实现
开发语言·qt
石山代码42 分钟前
C++ 内存分区 堆区
java·开发语言·c++
前端若水1 小时前
会话管理:创建、切换、删除对话历史
前端·人工智能·python·react.js
无风听海1 小时前
C# 隐式转换深度解析
java·开发语言·c#
涛声依旧-底层原理研究所2 小时前
残差连接与层归一化通俗易懂的详解
人工智能·python·神经网络·transformer
一只大袋鼠2 小时前
Git 进阶(二):分支管理、暂存栈、远程仓库与多人协作
java·开发语言·git
csdn_aspnet2 小时前
Python 算法快闪 LeetCode 编号 70 - 爬楼梯
python·算法·leetcode·职场和发展
fantasy_arch2 小时前
pytorch人脸匹配模型
人工智能·pytorch·python
熊猫_豆豆2 小时前
广义相对论水星近日点进动完整详细数学推导
python·天体·广义相对论
LuminousCPP2 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习