Java landing layered Structure design idea

Source: Internet
Author: User
Tags xpath

Entity class

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;    }}

Presentation layer:

//输入输出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("登陆失败");        }    }}

Business layer:

  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 {Loginu        I Loginui = new Loginui ();        Loginbusiness lognbusiness = new loginbusiness ();        User user = Loginui.input ();        Boolean flag = Lognbusiness.check (user);    Loginui.output (flag);        }//Judge 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; }}

File
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 landing layered Structure design idea

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.