工具类之字符串的脱敏操作

    public static String nickNameMasking(String nickName) {
        if (null!=nickName) {
            int length = nickName.length();
            if (length == 1) {
                return maskReplce(nickName, 0, 1);
            } else if (length == 2) {
                return maskReplce(nickName, 1, 2);
            } else {
                return maskReplce(nickName, 1, length - 1);
            }
        }
        return "*";
    }
    public static String maskReplce(String str, int start, int end) {
        int i = end - start;
        StringBuffer maskStr = new StringBuffer();
        for (int j = 0; j < i; j++) {
            maskStr.append("*");
        }
        StringBuilder sb = new StringBuilder(str);
        sb.replace(start, end, maskStr.toString());
        return sb.toString();
    }
上一篇:SpringBoot上传大型视频文件到服务器,解决方案


下一篇:webuploader上传文件夹讨论