Easily implement custom data desensitization returns

learning target:

实现简单的数据脱敏功能

For example:

  • Learn custom data masking

Learning Content:

使用到:泛型、反射

/**
     * 
     * @param obj 需要数据脱敏的对象
     * @param par 那些字段需要脱敏
     * @param <T>
     * @return
     * @throws Exception
     */
    public static <T> T transactionData(T obj,String... par)throws Exception{
    
    
        HashSet<String> msgSet = new HashSet<>();
        for (String item : par) {
    
    
            msgSet.add(item);
        }
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
    
    
            if (msgSet.contains(field.getName())) {
    
    
                field.setAccessible(true);
                field.set(obj,"******");
            }
        }
        return obj;
    }

Learning output:

提示:这里统计学习计划的总量

For example:

  • 1 technical note

Guess you like

Origin blog.csdn.net/m0_50677223/article/details/131984563