最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java數(shù)據(jù)脫敏常用方法(3種)

 更新時間:2023年07月14日 15:08:30   作者:y小恒  
數(shù)據(jù)脫敏常用在電話號碼和身份證號,本文主要介紹了Java數(shù)據(jù)脫敏常用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1.SQL數(shù)據(jù)脫敏實現(xiàn)

MYSQL(電話號碼,身份證)數(shù)據(jù)脫敏的實現(xiàn)

-- CONCAT()、LEFT()和RIGHT()字符串函數(shù)組合使用,請看下面具體實現(xiàn)
-- CONCAT(str1,str2,…):返回結(jié)果為連接參數(shù)產(chǎn)生的字符串
-- LEFT(str,len):返回從字符串str 開始的len 最左字符
-- RIGHT(str,len):從字符串str 開始,返回最右len 字符
-- 電話號碼脫敏sql:
SELECT mobilePhone AS 脫敏前電話號碼,CONCAT(LEFT(mobilePhone,3), '********' ) AS 脫敏后電話號碼 FROM t_s_user
-- 身份證號碼脫敏sql:
SELECT idcard AS 未脫敏身份證, CONCAT(LEFT(idcard,3), '****' ,RIGHT(idcard,4)) AS 脫敏后身份證號 FROM t_s_user

2.JAVA數(shù)據(jù)脫敏實現(xiàn)

可參考:海強(qiáng) / sensitive-plus

數(shù)據(jù)脫敏插件,目前支持地址脫敏、銀行卡號脫敏、中文姓名脫敏、固話脫敏、身份證號脫敏、手機(jī)號脫敏、密碼脫敏 一個是正則脫敏、另外一個根據(jù)顯示長度脫敏,默認(rèn)是正則脫敏,可以根據(jù)自己的需要配置自己的規(guī)則。

3 mybatis-mate-sensitive-jackson

mybatis-mate-sensitive-jackson

mybatisplus 的新作,可以測試使用,生產(chǎn)需要收費。

根據(jù)定義的策略類型,對數(shù)據(jù)進(jìn)行脫敏,當(dāng)然策略可以自定義。

# 目前已有
package mybatis.mate.strategy;
public interface SensitiveType {
    String chineseName = "chineseName";
    String idCard = "idCard";
    String phone = "phone";
    String mobile = "mobile";
    String address = "address";
    String email = "email";
    String bankCard = "bankCard";
    String password = "password";
    String carNumber = "carNumber";
}

Demo 代碼目錄

 1、pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-mate-examples</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>mybatis-mate-sensitive-jackson</artifactId>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
</project>

2、appliation.yml

# DataSource Config
spring:
  datasource:
#    driver-class-name: org.h2.Driver
#    schema: classpath:db/schema-h2.sql
#    data: classpath:db/data-h2.sql
#    url: jdbc:h2:mem:test
#    username: root
#    password: test
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatis_mate?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: root
    password: 123456
# Mybatis Mate 配置
mybatis-mate:
  cert:
    # 請?zhí)砑游⑿舧x153666購買授權(quán),不白嫖從我做起! 測試證書會失效,請勿正式環(huán)境使用
    grant: thisIsTestLicense
    license: as/bsBaSVrsA9FfjC/N77ruEt2/QZDrW+MHETNuEuZBra5mlaXZU+DE1ZvF8UjzlLCpH3TFVH3WPV+Ya7Ugiz1Rx4wSh/FK6Ug9lhos7rnsNaRB/+mR30aXqtlLt4dAmLAOCT56r9mikW+t1DDJY8TVhERWMjEipbqGO9oe1fqYCegCEX8tVCpToKr5J1g1V86mNsNnEGXujnLlEw9jBTrGxAyQroD7Ns1Dhwz1K4Y188mvmRQp9t7OYrpgsC7N9CXq1s1c2GtvfItHArkqHE4oDrhaPjpbMjFWLI5/XqZDtW3D+AVcH7pTcYZn6vzFfDZEmfDFV5fQlT3Rc+GENEg==
# Logger Config
logging:
  level:
    mybatis.mate: debug

3、Appliation啟動類

package mybatis.mate.sensitive.jackson;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SensitiveJacksonApplication {
    // 測試訪問 http://localhost:8080/info ,http://localhost:8080/list
    public static void main(String[] args) {
        SpringApplication.run(SensitiveJacksonApplication.class, args);
    }
}
 

4、配置類,自定義脫敏策略

package mybatis.mate.sensitive.jackson.config;
import mybatis.mate.databind.ISensitiveStrategy;
import mybatis.mate.strategy.SensitiveStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SensitiveStrategyConfig {
    /**
     * 注入脫敏策略
     */
    @Bean
    public ISensitiveStrategy sensitiveStrategy() {
        // 自定義 testStrategy 類型脫敏處理
        return new SensitiveStrategy().addStrategy("testStrategy", t -> t + "***test***");
    }
}

5、業(yè)務(wù)類

User,注解標(biāo)識脫敏字段,及選用脫敏策略

package mybatis.mate.sensitive.jackson.entity;
import lombok.Getter;
import lombok.Setter;
import mybatis.mate.annotation.FieldSensitive;
import mybatis.mate.sensitive.jackson.config.SensitiveStrategyConfig;
import mybatis.mate.strategy.SensitiveType;
@Getter
@Setter
public class User {
    private Long id;
    /**
     * 這里是一個自定義的策略 {@link SensitiveStrategyConfig} 初始化注入
     */
    @FieldSensitive("testStrategy")
    private String username;
    /**
     * 默認(rèn)支持策略 {@link SensitiveType }
     */
    @FieldSensitive(SensitiveType.mobile)
    private String mobile;
    @FieldSensitive(SensitiveType.email)
    private String email;
}

UserController

package mybatis.mate.sensitive.jackson.controller;
import mybatis.mate.databind.ISensitiveStrategy;
import mybatis.mate.databind.RequestDataTransfer;
import mybatis.mate.sensitive.jackson.entity.User;
import mybatis.mate.sensitive.jackson.mapper.UserMapper;
import mybatis.mate.strategy.SensitiveType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ISensitiveStrategy sensitiveStrategy;
    // 測試訪問 http://localhost:8080/info
    @GetMapping("/info")
    public User info() {
        return userMapper.selectById(1L);
    }
    // 測試返回 map 訪問 http://localhost:8080/map
    @GetMapping("/map")
    public Map<String, Object> map() {
        // 測試嵌套對象脫敏
        Map<String, Object> userMap = new HashMap<>();
        userMap.put("user", userMapper.selectById(1L));
        userMap.put("test", 123);
        userMap.put("userMap", new HashMap<String, Object>() {{
            put("user2", userMapper.selectById(2L));
            put("test2", "hi china");
        }});
        // 手動調(diào)用策略脫敏
        userMap.put("mobile", sensitiveStrategy.getStrategyFunctionMap()
                .get(SensitiveType.mobile).apply("15315388888"));
        return userMap;
    }
    // 測試訪問 http://localhost:8080/list
    // 不脫敏 http://localhost:8080/list?skip=1
    @GetMapping("/list")
    public List<User> list(HttpServletRequest request) {
        if ("1".equals(request.getParameter("skip"))) {
            // 跳過脫密處理
            RequestDataTransfer.skipSensitive();
        }
        return userMapper.selectList(null);
    }
}

UserMapper

package mybatis.mate.sensitive.jackson.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import mybatis.mate.sensitive.jackson.entity.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

6、測試

GET http://localhost:8080/list
[
  {
    "id": 1,
    "username": "Jone***test***",
    "mobile": "153******81",
    "email": "t****@baomidou.com"
  },
  {
    "id": 2,
    "username": "Jack***test***",
    "mobile": "153******82",
    "email": "t****@baomidou.com"
  },
  {
    "id": 3,
    "username": "Tom***test***",
    "mobile": "153******83",
    "email": "t****@baomidou.com"
  }
]
GET http://localhost:8080/list?skip&#61;1
[
  {
    "id": 1,
    "username": "Jone",
    "mobile": "15315388881",
    "email": "test1@baomidou.com"
  },
  {
    "id": 2,
    "username": "Jack",
    "mobile": "15315388882",
    "email": "test2@baomidou.com"
  },
  {
    "id": 3,
    "username": "Tom",
    "mobile": "15315388883",
    "email": "test3@baomidou.com"
  }
]

 到此這篇關(guān)于Java數(shù)據(jù)脫敏常用方法(3種)的文章就介紹到這了,更多相關(guān)Java數(shù)據(jù)脫敏內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java對int[]數(shù)組做新增刪除去重操作代碼

    Java對int[]數(shù)組做新增刪除去重操作代碼

    這篇文章主要介紹了Java里面對int[]數(shù)組做新增刪除去重實現(xiàn),這里記錄下使用int[]數(shù)組對數(shù)組進(jìn)行新增刪除去重等操作,用來更加了解java里面的集合類思想,需要的朋友可以參考下
    2023-10-10
  • 使用Iterator刪除List中的多個元素操作

    使用Iterator刪除List中的多個元素操作

    這篇文章主要介紹了使用Iterator刪除List中的多個元素操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Spring 中的 @PathVariable 注解及應(yīng)用場景分析

    Spring 中的 @PathVariable 注解及應(yīng)用場景分析

    @PathVariable注解是 Spring 框架中一個非常實用的注解,它可以幫助我們輕松地從 URL 中提取參數(shù),從而實現(xiàn) RESTful API 的開發(fā),通過本文的介紹,我們了解了@PathVariable注解的基本使用方法和高級用法,以及它的應(yīng)用場景,感興趣的朋友跟隨小編一起看看吧
    2025-05-05
  • Java Synchronized字節(jié)碼層分析體驗

    Java Synchronized字節(jié)碼層分析體驗

    這篇文章主要介紹了Java Synchronized字節(jié)碼層分析,synchronized關(guān)鍵字解決了多個線程之間的資源同步性,synchronized關(guān)鍵字保證了它修飾的方法或者代碼塊任意時刻只有一個線程在訪問
    2023-04-04
  • SpringBoot項目啟動時如何將需要數(shù)據(jù)添加到redis緩存

    SpringBoot項目啟動時如何將需要數(shù)據(jù)添加到redis緩存

    文章介紹了使用Java注解@PostConstruct進(jìn)行項目啟動時加載,并使用Spring和Redis進(jìn)行數(shù)據(jù)緩存的操作,通過`setCacheObject`方法將數(shù)據(jù)存儲到Redis中,并提供了清空緩存的方法
    2026-04-04
  • 一文帶你詳細(xì)認(rèn)識文件與Java中操作文件

    一文帶你詳細(xì)認(rèn)識文件與Java中操作文件

    文件處理是任何應(yīng)用程序的重要部分,Java 提供了許多用于創(chuàng)建、讀取、更新和刪除文件的方法,這篇文章主要給大家介紹了關(guān)于認(rèn)識文件與Java中操作文件的相關(guān)資料,需要的朋友可以參考下
    2024-05-05
  • Hadoop源碼分析六啟動文件namenode原理詳解

    Hadoop源碼分析六啟動文件namenode原理詳解

    本篇是Hadoop源碼分析系列文章第六篇,主要介紹Hadoop中的啟動文件namenode,后續(xù)本系列文章會持續(xù)更新,有需要的朋友可以借鑒參考下
    2021-09-09
  • 詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

    詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

    這篇文章主要介紹了詳解mybatis.generator配上最新的mysql 8.0.11的一些坑,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-10-10
  • @feignclient名字沖突的解決方案

    @feignclient名字沖突的解決方案

    這篇文章主要介紹了@feignclient名字沖突的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java連接Oracle數(shù)據(jù)庫并查詢

    Java連接Oracle數(shù)據(jù)庫并查詢

    這篇文章主要介紹了Java連接Oracle數(shù)據(jù)庫并查詢的相關(guān)資料,需要的朋友可以參考下
    2017-04-04

最新評論

宁陕县| 剑川县| 赣州市| 肥乡县| 睢宁县| 怀仁县| 景宁| 肇源县| 博客| 阿图什市| 二连浩特市| 建德市| 含山县| 山阴县| 镇巴县| 镇雄县| 普格县| 开化县| 澄城县| 阿瓦提县| 黑水县| 集贤县| 望谟县| 长泰县| 林周县| 科技| 日照市| 山东省| 高台县| 大关县| 陵川县| 广昌县| 腾冲县| 朝阳区| 湛江市| 抚远县| 富锦市| 汝州市| 唐山市| 怀化市| 融水|