程序中不应对邮箱地址进行硬编码,可以使用配置文件或数据库存储的方式来存储系统所需的数据;并且录入数据时,还可以在对敏感数据做加密处理之后再进行数据的录入。

    1. public class UserDAO {
    2. private static Map<Integer, User> users = new LinkedHashMap<Integer, User>();
    3. static {
    4. users.put(1001, new User(1001, "韩信", 22, EncryptUtil.encrypt(phoneDAO.getPhoneById(1001)), EncryptUtil.encrypt(emailDAO.getEmailById(1001))));
    5. users.put(1002, new User(1002, "张良", 30, EncryptUtil.encrypt(phoneDAO.getPhoneById(1002)), EncryptUtil.encrypt(emailDAO.getEmailById(1002))));
    6. users.put(1003, new User(1003, "萧何", 27, EncryptUtil.encrypt(phoneDAO.getPhoneById(1003)), EncryptUtil.encrypt(emailDAO.getEmailById(1003))));
    7. // ...
    8. }
    9. // 用户信息的增删改查方法
    10. // ...
    11. }
    12. public class User {
    13. private int id;
    14. private String name;
    15. private int age;
    16. private String tel;
    17. private String email;
    18. public User() {}
    19. public User(int id, String name, int age, String tel, String email) {
    20. this.id = id;
    21. this.name = name;
    22. this.age = age;
    23. this.tel = tel;
    24. this.email = email;
    25. }
    26. // Getter and Setter
    27. // ...
    28. }