java 登陆分层结构设计思想
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 登陆分层结构设计思想的主要内容,如果未能解决你的问题,请参考以下文章