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

4.3.3.3创建EmployeeDAO类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;
day01-3-界面显示&amp;用户登录&amp;餐桌状态显示

文章插图
4.4.3.2创建DiningTable类package com.li.mhl.domain;/** * @author 李 * @version 1.0 * 这是一个Javabean,和表 diningTable对应 */public class DiningTable {/*** FieldTypeNullKeyDefaultExtra* -------------------------------------------------------* idint(11)NOPRI(NULL)auto_increment* statevarchar(20)NO* orderNamevarchar(50)NO* orderTelvarchar(20)NO*/private Integer id;private String state;private String orderName;private String orderTel;public DiningTable() {//无参构造器,反射需要}public DiningTable(Integer id, String state, String orderName, String orderTel) {this.id = id;this.state = state;this.orderName = orderName;this.orderTel = orderTel;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getState() {return state;}public void setState(String state) {this.state = state;}public String getOrderName() {return orderName;}public void setOrderName(String orderName) {this.orderName = orderName;}public String getOrderTel() {return orderTel;}public void setOrderTel(String orderTel) {this.orderTel = orderTel;}@Overridepublic String toString() {returnid + "\t\t\t" + state;}}4.4.3.3创建DiningTableDAO类package com.li.mhl.dao;import com.li.mhl.domain.DiningTable;/** * @author 李 * @version 1.0 */public class DiningTableDAO extends BasicDAO<DiningTable>{//如果有特别的操作 , 可以写在DiningTableDAO中}4.4.3.4创建DiningTableService类package com.li.mhl.service;import com.li.mhl.dao.DiningTableDAO;import com.li.mhl.domain.DiningTable;import java.util.List;/** * @author 李 * @version 1.0 * 该类完成对 diningTable表的各种操作(通过调用DiningTableDAO对象完成) */public class DiningTableService {//业务层//定义一个DiningTableDAO对象private DiningTableDAO diningTableDAO = new DiningTableDAO();//返回所有餐桌的信息public List<DiningTable> list(){List<DiningTable> diningTables =diningTableDAO.queryMulti("select id,state from diningTable", DiningTable.class);return diningTables;}}4.4.3.5修改MHLView类修改处1:增加DiningTableService属性
//定义DiningTableService属性private DiningTableService diningTableService=new DiningTableService();修改处2:增加listDiningTable()方法,显示餐桌信息
//显示餐桌状态public void listDiningTable(){List<DiningTable> list = diningTableService.list();System.out.println("\n餐桌编号\t\t餐桌状态");for (DiningTable diningTable:list) {System.out.println(diningTable);}System.out.println("============显示完毕============");}

推荐阅读