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();
文章插图
修改处2:
文章插图
4.4显示餐桌状态4.4.1功能说明当用户登录成功之后,选择显示餐桌状态,可以看到所有的餐桌编号以及对应的餐桌状态
文章插图
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;
文章插图
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("============显示完毕============");}
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ubuntu20.04 利用xrandr命令修改多显示器分辨率
- 手机如何连接电脑界面(手机连接电脑设置界面)
- MFC-创建MFC图形界面dll
- vivox50熄屏幕显示时间设置_vivox50熄屏怎么显示时间
- 15 基于SqlSugar的开发框架循序渐进介绍-- 整合代码生成工具进行前端界面的生成
- 电脑中怎么隐藏文件夹,怎么显示隐藏的文件
- 手机隐藏文件夹怎么显示(手机隐藏文件夹怎么显示oppo)
- 怎样显示隐藏的文件夹(电脑怎么调出隐藏文件)
- 电脑c盘怎么显示隐藏的文件夹(电脑怎么调出隐藏文件)
- 微信小程序中视频的显示与隐藏