欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java掩碼的幾種使用例舉

 更新時(shí)間:2019年03月14日 10:01:56   作者:Alan_阿蘭  
今天小編就為大家分享一篇關(guān)于Java掩碼的使用,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧

java掩碼

 private static String nameMask(String name) throws Exception {
 if(name ==null)throw new Exception("請(qǐng)輸入要掩碼的字符串");
 if(name.length()<=1) return name+"*";
 return name.replaceAll("([\\u4e00-\\u9fa5]{1})(.*)", "$1"+createAsterisk(name.length()-1));
 }
 private static String createAsterisk(int len) {
 StringBuffer sb = new StringBuffer();
 for(int i=0;i<len;i++){
  sb.append("*");
 }
 return sb.toString();
 }
/**
 * 對(duì)客戶證件號(hào)碼做掩碼
 * 
 * */
 public static String maskCertId(String certId) throws Exception
 {
 if(certId==null||certId.length()==0) return "";
 if(certId.length()==18)
 {
  String v = certId.substring(0,4);
  String end = certId.substring(certId.length()-4);
  return v+StringUtils.repeat("*",8)+end;
 }
 else
  return "";
 }
/**
 * 對(duì)客戶姓名做掩碼
 * @throws JBOException 
 * */
 public static String maskUserName(String userName) throws Exception
 {
 if(userName==null||userName.length()==0) return "";
 String v = userName.substring(0,1);
 return StringUtils.rightPad(v, userName.length(),"*");//StringUtils.rightPad方法做一個(gè)字符串右補(bǔ)齊
 }
/**
 * 對(duì)字符串進(jìn)行脫敏處理
 * @param word 被脫敏的字符
 * @param startLength 被保留的開(kāi)始長(zhǎng)度 0代表不保留
 * @param endLength 被保留的結(jié)束長(zhǎng)度 0代表不保留
 * @param pad 填充字符
 * */
 public static String wordMask(String word,int startLength ,int endLength,String pad)  {
 if(word==null) return StringUtils.leftPad("", startLength+endLength,pad);
 if(word.length()<=startLength+endLength) return StringUtils.leftPad("", startLength+endLength,pad);
 String startStr = "";
 String endStr = "";
 int padLength = 0;
 if(word.length()>startLength) startStr = StringUtils.substring(word, 0,startLength);
 if(word.length()>startLength+endLength) endStr = StringUtils.substring(word, word.length()-endLength);
 padLength = word.length()-startLength-endLength;
 return startStr + StringUtils.repeat(pad, padLength)+endStr;
 }

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

  • spring定義和裝配bean詳解

    spring定義和裝配bean詳解

    這篇文章主要介紹了spring定義和裝配bean詳解,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • 在Java中int和byte[]的相互轉(zhuǎn)換

    在Java中int和byte[]的相互轉(zhuǎn)換

    這篇文章主要介紹了在Java中int和byte[]的相互轉(zhuǎn)換的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • Junit springboot打印測(cè)試方法信息

    Junit springboot打印測(cè)試方法信息

    這篇文章主要介紹了Junit springboot打印測(cè)試方法信息,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • SpringBoot實(shí)現(xiàn)整合微信支付方法詳解

    SpringBoot實(shí)現(xiàn)整合微信支付方法詳解

    這篇文章主要介紹了SpringBoot實(shí)現(xiàn)整合微信支付的過(guò)程詳解,文中的示例代碼對(duì)我們的工作或?qū)W習(xí)有一定的幫助,感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下
    2021-12-12
  • 使用ehcache三步搞定springboot緩存的方法示例

    使用ehcache三步搞定springboot緩存的方法示例

    本次內(nèi)容主要介紹基于Ehcache 3.0來(lái)快速實(shí)現(xiàn)Spring Boot應(yīng)用程序的數(shù)據(jù)緩存功能。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-04-04
  • SpringCloud-Gateway轉(zhuǎn)發(fā)WebSocket失敗問(wèn)題及解決

    SpringCloud-Gateway轉(zhuǎn)發(fā)WebSocket失敗問(wèn)題及解決

    這篇文章主要介紹了SpringCloud-Gateway轉(zhuǎn)發(fā)WebSocket失敗問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java/Android 獲取網(wǎng)絡(luò)重定向文件的真實(shí)URL的示例代碼

    Java/Android 獲取網(wǎng)絡(luò)重定向文件的真實(shí)URL的示例代碼

    本篇文章主要介紹了Java/Android 獲取網(wǎng)絡(luò)重定向文件的真實(shí)URL的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 在Spring Boot中實(shí)現(xiàn)HTTP緩存的方法

    在Spring Boot中實(shí)現(xiàn)HTTP緩存的方法

    緩存是HTTP協(xié)議的一個(gè)強(qiáng)大功能,但由于某些原因,它主要用于靜態(tài)資源,如圖像,CSS樣式表或JavaScript文件。本文重點(diǎn)給大家介紹在Spring Boot中實(shí)現(xiàn)HTTP緩存的方法,感興趣的朋友跟隨小編一起看看吧
    2018-10-10
  • Spring深入分析容器接口作用

    Spring深入分析容器接口作用

    Spring內(nèi)部提供了很多表示Spring容器的接口和對(duì)象,我們今天來(lái)看看幾個(gè)比較常見(jiàn)的容器接口和具體的實(shí)現(xiàn)類,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • 解決IDEA target文件夾越來(lái)越大的問(wèn)題

    解決IDEA target文件夾越來(lái)越大的問(wèn)題

    這篇文章主要介紹了解決IDEA target文件夾越來(lái)越大的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-02-02

最新評(píng)論