- package com.cys.dao;
- /**
- * 这是user的控制接口,接口实现了两种登录注册的主要控制
- * @author 游呤人
- * */
- import com.cys.pojo.User;
- public interface UserDao {
- public abstract boolean login(String usrname,String password);
- public abstract boolean register(User user);
- }
复制代码
- package com.cys.dao.imp;
- import java.util.ArrayList;
- import java.util.List;
- import com.cys.dao.UserDao;
- import com.cys.pojo.User;
- /**
- * 这是user的控制接口的实现类
- * @author 游呤人
- * */
- public class UserDaoimp implements UserDao {
- private List<User> list=new ArrayList<User>();
- private UserDaoimp(){}
- //使用单例模式,Dao在内存中只有一份,
- private static final UserDaoimp userDao= new UserDaoimp(); //
-
- public static UserDaoimp getInstens(){
- return userDao;
- }
- //登录功能
- @Override
- public boolean login(String usrname,String password){
- for (User user : list) {
- if(user.getPassword().equals(usrname)&&user.getPassword().equals(password)){
- return true;
- }
- }
- return false;
-
- }
- //注册功能
- public boolean register(User user){
- list.add(user);
- return true;
- }
- }
复制代码
- package com.cys.pojo;
- /**
- *
- * User 的实体类
- * */
- public class User {
- String username;
- String password;
- String mail;
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getMail() {
- return mail;
- }
- public void setMail(String mail) {
- this.mail = mail;
- }
-
-
- }
复制代码
|
|