程序中不应对邮箱地址进行硬编码,可以使用配置文件或数据库存储的方式来存储系统所需的数据;并且录入数据时,还可以在对敏感数据做加密处理之后再进行数据的录入。
public class UserDAO {
private static Map<Integer, User> users = new LinkedHashMap<Integer, User>();
static {
users.put(1001, new User(1001, "韩信", 22, EncryptUtil.encrypt(phoneDAO.getPhoneById(1001)), EncryptUtil.encrypt(emailDAO.getEmailById(1001))));
users.put(1002, new User(1002, "张良", 30, EncryptUtil.encrypt(phoneDAO.getPhoneById(1002)), EncryptUtil.encrypt(emailDAO.getEmailById(1002))));
users.put(1003, new User(1003, "萧何", 27, EncryptUtil.encrypt(phoneDAO.getPhoneById(1003)), EncryptUtil.encrypt(emailDAO.getEmailById(1003))));
// ...
}
// 用户信息的增删改查方法
// ...
}
public class User {
private int id;
private String name;
private int age;
private String tel;
private String email;
public User() {}
public User(int id, String name, int age, String tel, String email) {
this.id = id;
this.name = name;
this.age = age;
this.tel = tel;
this.email = email;
}
// Getter and Setter
// ...
}