day01-3-界面显示&用户登录&餐桌状态显示

满汉楼01-34.功能实现024.2菜单界面显示4.2.1功能说明显示主菜单、二级菜单和退出系统功能

day01-3-界面显示&用户登录&餐桌状态显示

文章插图
day01-3-界面显示&用户登录&餐桌状态显示

文章插图
4.2.2代码实现先搭建界面显示的大体框架,具体的功能后面再实现
创建MHLView类:
package com.li.mhl.view;import com.li.mhl.utils.Utility;/** * @author 李 * @version 1.0 * 这是主界面 */public class MHLView {//控制是否退出菜单private boolean loop = true;private String key = "";//接收用户的输入public static void main(String[] args) {new MHLView().mainMenu();}//显示主菜单public void mainMenu() {while (loop) {System.out.println("==================满汉楼==================");System.out.println("\t\t 1 登录满汉楼");System.out.println("\t\t 2 退出满汉楼");System.out.print("请输入你的选择:");key = Utility.readString(1);//接收用户选择switch (key) {case "1":System.out.print("请输入员工号: ");String id=Utility.readString(50);System.out.print("请输入密码: ");String pws = Utility.readString(50);//到数据库去判断,这里先简单判断一下if ("123".equals(pws)) {System.out.println("==================登录成功=================\n");//显示二级菜单,这里也和一级菜单一样是循环操作,也放在循环语句中while (loop){System.out.println("==================满汉楼(二级菜单)==================");System.out.println("\t\t 1 显示餐桌状态");System.out.println("\t\t 2 预定餐桌");System.out.println("\t\t 3 显示所有菜品");System.out.println("\t\t 4 点餐服务");System.out.println("\t\t 5 参看账单");System.out.println("\t\t 6 结账");System.out.println("\t\t 9 退出满汉楼");System.out.print("请输入你的选择:");key = Utility.readString(1);//接收用户的选择switch(key){case "1":System.out.println("显示餐桌状态");break;case "2":System.out.println("预定餐桌");break;case "3":System.out.println("显示所有菜品");break;case "4":System.out.println("点餐服务");break;case "5":System.out.println("参看账单");break;case "6":System.out.println("结账");break;case "9"://因为loop同时控制两层循环 , 因此当loop设为false时,// 里层循环退出之后,外层循环也会随之退出loop=false;break;default:System.out.println("输入有误 , 请重新输入");break;}}}else {System.out.println("==================登录失败==================");}break;case "2":loop = false;//退出一级菜单的循环break;default:System.out.println("输入有误,重新输入..");}}System.out.println("你退出了满汉楼系统~");}}4.3用户登录功能4.3.1功能说明【day01-3-界面显示&用户登录&餐桌状态显示】
day01-3-界面显示&用户登录&餐桌状态显示

文章插图

day01-3-界面显示&用户登录&餐桌状态显示

文章插图
4.3.2思路分析在数据库创建一张employee表,创建对应的Javabean,创建对应的EmployeeDAO,service层...
(大体上就是根据框架图从下至上编写代码)
4.3.3代码实现4.3.3.1创建数据库mhl和表employee-- 创建满汉楼的数据库CREATE DATABASE mhl;-- 创建表employee(主键id,empId,name,pwd,job等)CREATE TABLE employee( id INT PRIMARY KEY AUTO_INCREMENT,#自增 empId VARCHAR(50) UNIQUE NOT NULL DEFAULT '',#员工号 pwd CHAR(32) NOT NULL DEFAULT '',#密码md5 NAME VARCHAR(50) NOT NULL DEFAULT '',#姓名 job VARCHAR(50) NOT NULL DEFAULT ''#岗位)CHARSET=utf8-- 插入测试数据INSERT INTO employee VALUES(NULL,'6668612',MD5('123456'),'张三丰','经理');INSERT INTO employee VALUES(NULL,'6668622',MD5('123456'),'小龙女','服务员');INSERT INTO employee VALUES(NULL,'6668633',MD5('123456'),'张无忌','收银员');INSERT INTO employee VALUES(NULL,'666666',MD5('123456'),'olien','经理');SELECT * FROM employee;
day01-3-界面显示&用户登录&餐桌状态显示

文章插图
4.3.3.2创建Employee类创建和表employee对应的Javabean-Employee
package com.li.mhl.domain;/** * @author 李 * @version 1.0 * 这是一个Javabean ,和表employee对应 */public class Employee {/*** +-------+-------------+------+-----+---------+----------------+* | Field | Type| Null | Key | Default | Extra|* +-------+-------------+------+-----+---------+----------------+* | id| int(11)| NO| PRI | NULL| auto_increment |* | empId | varchar(50) | NO||||* | pwd| char(32)| NO||||* | name| varchar(50) | NO||||* | job| varchar(50) | NO||||* +-------+-------------+------+-----+---------+----------------+*/private Integer id;private String empId;private String pwd;private String name;private String job;public Employee() {//无参构造器,底层的Apache-DBUtils反射需要}public Employee(Integer id, String empId, String pwd, String name, String job) {this.id = id;this.empId = empId;this.pwd = pwd;this.name = name;this.job = job;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getEmpId() {return empId;}public void setEmpId(String empId) {this.empId = empId;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getJob() {return job;}public void setJob(String job) {this.job = job;}@Overridepublic String toString() {return "Employee{" +"id=" + id +", empId='" + empId + '\'' +", pwd='" + pwd + '\'' +", name='" + name + '\'' +", job='" + job + '\'' +'}';}}

推荐阅读