码迷,mamicode.com
首页 > 编程语言 > 详细

java 登陆分层结构设计思想

时间:2018-04-16 16:15:20      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:java 登陆分层结构设计思想

实体类

public class User {

    private String id;
    private String username;
    private String password;
    public User(){}
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    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 class LoginUI {

    public User input()
    {
        User user = new User();
        Scanner scanner = new Scanner(System.in);
        System.out.print("用户名:");
        String username = scanner.nextLine();
        System.out.print("密码:");
        String password = scanner.nextLine();
        user.setUsername(username);
        user.setPassword(password);

        return user;
    }

    public void output(boolean flag)
    {
        if(flag)
        {
            System.out.println("登陆成功");
        }else
        {
            System.out.println("登陆失败");
        }
    }

}

业务层:


import java.io.File;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;

public class LoginBusiness {

    @Test
    public void logingtet() throws Exception
    {
        LoginUI loginUI = new LoginUI();
        LoginBusiness lognBusiness = new LoginBusiness();

        User user = loginUI.input();
        boolean flag = lognBusiness.check(user);

        loginUI.output(flag);
    }

    //判断
    public boolean check(User user) throws Exception
    {
        boolean flag = false;
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File("src/day2/domx/users.xml"));
        String xpath = "//user[@username=‘"+user.getUsername()+"‘ and @password=‘"+user.getPassword()+"‘]";
        Element element = (Element) document.selectSingleNode(xpath);
        if(element !=null)
        {
            flag = true;
        }
        return flag;    
    }

}

文件
user.xml
<?xml version="1.0" encoding="UTF-8"?>

-<root>

<user password="123456" username="liwen" id="id001"/>

<user password="23456" username="python" id="id002"/>

</root>

java 登陆分层结构设计思想

标签:java 登陆分层结构设计思想

原文地址:http://blog.51cto.com/357712148/2103971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!