身份证适用于二代身份证18位(基于正则表达式)
//前提是18位
authOtherPayeeDO.setOtherPayeeIdNumber(authOtherPayeeDO.getOtherPayeeIdNumber().replaceAll("(\\w{6})\\w*(\\w{4})", "$1*********$2"));
authOtherPayeeDO.setOtherPayeePhone(authOtherPayeeDO.getOtherPayeePhone().replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2"));
或者在查询数据库时对该字段脱敏(下边是对手机号,身份证号可模仿)
a.contact_telephone,
CONCAT(LEFT(a.contact_telephone, 3), "****", RIGHT(a.contact_telephone, 4)) AS hideTelephone
开发中常见的页面信息(手机号,身份证号码)我们需要对用户数据进行脱敏处理,可参考上述代码示例