1. 按照数据model, 创建DAO层
2. 在UserDao中, 添加控制user的相关数据库操作:
public class UserDao {
public boolean isExist(String username) {
return DBUtil.userMap.containsKey(username);
}
public boolean addUser(String username,String password,int age,String gender) {
if(isExist(username)) {
return false;
}
User u = new User(username,password,age,gender,false);
DBUtil.userMap.put(u.getUsername(), u);
return true;
}
public User getUserByUP(String username,String password) { // U = Username, P = Password
if(isExist(username)==false) {
return null;
}
User u = DBUtil.userMap.get(username);
if(u.getPassword().equals(password)) {
return u;
}else {
return null;
}
}
}