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


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 + '\'' +'}';}}4.3.3.3创建EmployeeDAO类【day01-3-界面显示&用户登录&餐桌状态显示】package com.li.mhl.dao;import com.li.mhl.domain.Employee;/** * @author 李 * @version 1.0 */public class EmployeeDAO extends BasicDAO<Employee>{//这里还可以执行特有的操作}4.3.3.4创建EmployeeService类编写一个getEmployeeByIdAndPwd方法 , 来验证账号密码 , 并返回相应值
package com.li.mhl.service;import com.li.mhl.dao.EmployeeDAO;import com.li.mhl.domain.Employee;/** * @author 李 * @version 1.0 * 该类完成对employee表的各种操作(通过调用EmployeeDAO对象完成) */public class EmployeeService {//定义一个EmployeeDAO属性private EmployeeDAO employeeDAO = new EmployeeDAO();//登录校验方法//根据empId和pwd返回一个Employee对象,如果查询不到 , 就返回nullpublic Employee getEmployeeByIdAndPwd(String empId, String pwd) {//注意密码使用md5加密后再查询比较Employee employee =employeeDAO.querySingle("select * from employee where empId=? and pwd=md5(?) ", Employee.class, empId, pwd);return employee;}}4.3.3.5修改MHLView类在MHLView类中的里层循环中 , 调用方法getEmployeeByIdAndPwd , 如果返回的employee对象非空 , 则说明存在该用户 , 登录成功
修改处1:增加EmployeeService属性
//定义EmployeeService属性private EmployeeService employeeService=new EmployeeService();
day01-3-界面显示&amp;用户登录&amp;餐桌状态显示

文章插图
修改处2:
day01-3-界面显示&amp;用户登录&amp;餐桌状态显示

文章插图
4.4显示餐桌状态4.4.1功能说明当用户登录成功之后 , 选择显示餐桌状态 , 可以看到所有的餐桌编号以及对应的餐桌状态
day01-3-界面显示&amp;用户登录&amp;餐桌状态显示

文章插图
4.4.2思路分析创建表diningTable , 创建对应的Javabean , 创建对应的DAO , service层...
4.4.3代码实现4.4.3.1创建diningTable表-- 创建表diningTable(主键id,empId,name,pwd,job等)CREATE TABLE diningTable( id INT PRIMARY KEY AUTO_INCREMENT,#自增 , 表示餐桌编号 state VARCHAR(20)NOT NULL DEFAULT '',#餐桌状态 orderName VARCHAR(50) NOT NULL DEFAULT '',#预定人的名字 orderTel VARCHAR(20) NOT NULL DEFAULT ''#预定人的电话)CHARSET=utf8-- 插入测试数据INSERT INTO diningTable VALUES(NULL,'空','','');INSERT INTO diningTable VALUES(NULL,'空','','');INSERT INTO diningTable VALUES(NULL,'空','','');SELECT * FROM diningTable;

经验总结扩展阅读