java实现简单的脱敏操作
所谓脱敏就是:隐藏掉信息中的一部分关键信息,用*代替,自定义隐藏可以使用StrUtil.hide方法完成。
import cn.hutool.core.util.DesensitizedUtil;
import cn.下边的类.IdCardBO;
import java.util.ArrayList;
import java.util.List;
public class DesensitizedDemo {
public static void main(String[] args) {
IdCardBO bo1 = new IdCardBO(
1L,
"13022720040312382x",
"15033568702");
IdCardBO bo2 = new IdCardBO(
2L,
"130224200404066615",
"17343568701");
List<IdCardBO> list = new ArrayList<>();
list.add(bo1);
list.add(list.size(),bo2);
list.forEach(e ->{
String idCard = DesensitizedUtil.idCardNum(e.getCard(), 6, 4);
e.setCard(idCard);
String phone = DesensitizedUtil.mobilePhone(e.getPhone());
e.setPhone(phone);
});
for (IdCardBO i : list){
System.out.println(i.getCard());
System.out.println(i.getPhone());
}
}
}
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class IdCardBO {
@ApiModelProperty("id")
private Long id;
@ApiModelProperty(value = "身份证号")
private String card;
@ApiModelProperty(value = "联系方式")
private String phone;
}