Mysql:

    select REPLACE(idcard, SUBSTR(mobile,4,12), '************') idcard from sys_users
    select insert(idcard,4, 12, '*************') idcard from sys_users ;

 

java代码:
1、身份证可能是18为或者15位

if (newTBProjectCorpInfo.getPersonidcard().length() == 18) {
            newTBProjectCorpInfo.setPersonidcard(newTBProjectCorpInfo.getPersonidcard().replaceAll("(\\d{4})\\d{10}(\\d{4})", "$1****$2"));
        } else if (newTBProjectCorpInfo.getPersonidcard().length() == 15) {
            newTBProjectCorpInfo.setPersonidcard(newTBProjectCorpInfo.getPersonidcard().replaceAll("(\\d{4})\\d{8}(\\d{4})", "$1****$2"));
        }

2, 对

User.setPersonidcard(User.getPersonidcard().replaceAll("(\\w{4})\\w{0,}(\\w{4})", "$1****$2"));