满汉楼小项目

满汉楼(餐馆)

大家好,我是小笙,我完成了韩老师的满汉楼小项目,主要是练习java操作数据库的项目,项目虽然很简陋,但是我觉得可以学到很多基础的东西,不妨大家也来看看!


准备类库

jar包:commins_dbutils-1.3.jar | | druid-1.1.10.jar | | mysql-connector-java-5.1.37-bin.jar

工具类

// JDBCUtilsByDruid.java
public class JDBCUtilsByDruid {
    private static DataSource dataSource;

    static {
        String filePath = "E:\\Java_training\\Java_code\\JavaIdea03\\java" +
                "\\Javase_HSping\\src\\com\\Al_tair\\mhlProject\\utils\\druid.properties";
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(filePath));
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    // 连接数据库
    public static Connection getConnection(){
        try {
            // 创建一个指定参数的数据库连接池(德鲁伊连接池)
            return dataSource.getConnection();
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
    }

    // 查询语句关闭
    public static void closeQueryConnection(Connection connection, Statement statement, ResultSet rst){
        try {
            rst.close();
            statement.close();
            connection.close();
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
    }

    // dml语句操作关闭
    public static void closeDmlConnection(Connection connection,Statement statement){
        try {
            statement.close();
            connection.close();
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
    }

    public static void closeConnection(Connection connection){
        try {
            connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}

// Utility
// 工具类的作用:
// 处理各种情况的用户输入,并且能够按照程序员的需求,得到用户的控制台输入。
public class Utility {
	//静态属性。。。
    private static Scanner scanner = new Scanner(System.in);

    
    /**
     * 功能:读取键盘输入的一个菜单选项,值:1——5的范围
     * @return 1——5
     */
	public static char readMenuSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);//包含一个字符的字符串
            c = str.charAt(0);//将字符串转换成字符char类型
            if (c != '1' && c != '2' && 
                c != '3' && c != '4' && c != '5') {
                System.out.print("选择错误,请重新输入:");
            } else break;
        }
        return c;
    }

	/**
	 * 功能:读取键盘输入的一个字符
	 * @return 一个字符
	 */
    public static char readChar() {
        String str = readKeyBoard(1, false);//就是一个字符
        return str.charAt(0);
    }
    /**
     * 功能:读取键盘输入的一个字符,如果直接按回车,则返回指定的默认值;否则返回输入的那个字符
     * @param defaultValue 指定的默认值
     * @return 默认值或输入的字符
     */
    
    public static char readChar(char defaultValue) {
        String str = readKeyBoard(1, true);//要么是空字符串,要么是一个字符
        return (str.length() == 0) ? defaultValue : str.charAt(0);
    }
	
    /**
     * 功能:读取键盘输入的整型,长度小于2位
     * @return 整数
     */
    public static int readInt() {
        int n;
        for (; ; ) {
            String str = readKeyBoard(2, false);//一个整数,长度<=2位
            try {
                n = Integer.parseInt(str);//将字符串转换成整数
                break;
            } catch (NumberFormatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }
    /**
     * 功能:读取键盘输入的 整数或默认值,如果直接回车,则返回默认值,否则返回输入的整数
     * @param defaultValue 指定的默认值
     * @return 整数或默认值
     */
    public static int readInt(int defaultValue) {
        int n;
        for (; ; ) {
            String str = readKeyBoard(10, true);
            if (str.equals("")) {
                return defaultValue;
            }
			
			//异常处理...
            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }

    /**
     * 功能:读取键盘输入的指定长度的字符串
     * @param limit 限制的长度
     * @return 指定长度的字符串
     */

    public static String readString(int limit) {
        return readKeyBoard(limit, false);
    }

    /**
     * 功能:读取键盘输入的指定长度的字符串或默认值,如果直接回车,返回默认值,否则返回字符串
     * @param limit 限制的长度
     * @param defaultValue 指定的默认值
     * @return 指定长度的字符串
     */
	
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }


	/**
	 * 功能:读取键盘输入的确认选项,Y或N
	 * 将小的功能,封装到一个方法中.
	 * @return Y或N
	 */
    public static char readConfirmSelection() {
        System.out.print("确认是否预订(Y/N): ");
        char c;
        for (; ; ) {//无限循环
        	//在这里,将接受到字符,转成了大写字母
        	//y => Y n=>N
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'Y' || c == 'N') {
                break;
            } else {
                System.out.print("选择错误,请重新输入:");
            }
        }
        return c;
    }

    /**
     * 功能: 读取一个字符串
     * @param limit 读取的长度
     * @param blankReturn 如果为true ,表示 可以读空字符串。 
     * 					  如果为false表示 不能读空字符串。
     * 			
	 *	如果输入为空,或者输入大于limit的长度,就会提示重新输入。
     * @return
     */
    private static String readKeyBoard(int limit, boolean blankReturn) {
        
		//定义了字符串
		String line = "";

		//scanner.hasNextLine() 判断有没有下一行
        while (scanner.hasNextLine()) {
            line = scanner.nextLine();//读取这一行
           
			//如果line.length=0, 即用户没有输入任何内容,直接回车
			if (line.length() == 0) {
                if (blankReturn) return line;//如果blankReturn=true,可以返回空串
                else continue; //如果blankReturn=false,不接受空串,必须输入内容
            }

			//如果用户输入的内容大于了 limit,就提示重写输入  
			//如果用户如的内容 >0 <= limit ,我就接受
            if (line.length() < 1 || line.length() > limit) {
                System.out.print("输入长度(不能大于" + limit + ")错误,请重新输入:");
                continue;
            }
            break;
        }

        return line;
    }
}

// druid.properties配置文件(需要自己重新配置)
#key=value
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3308/al_tair?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=UTF-8
username=root
password=XXXXXXX
#initial connection Size
initialSize=10
#min idle connecton size
minIdle=5
#max active connection size
maxActive=50
#max wait time (5000 mil seconds)
maxWait=5000

主菜单(View层)

package com.Al_tair.mhlProject.view;

import com.Al_tair.mhlProject.domain.Bill;
import com.Al_tair.mhlProject.domain.Employee;
import com.Al_tair.mhlProject.domain.MHLTable;
import com.Al_tair.mhlProject.service.BillService;
import com.Al_tair.mhlProject.service.EmployeeService;
import com.Al_tair.mhlProject.service.MHLTableService;
import com.Al_tair.mhlProject.service.MenuService;
import com.Al_tair.mhlProject.utils.Utility;

import java.util.List;

public class Menu {
    private boolean loop = true;
    private String choice = "";

    private EmployeeService employeeService = new EmployeeService();
    private MHLTableService mhlTableService = new MHLTableService();
    private MenuService menuService = new MenuService();
    private BillService billService = new BillService();


    /**
     * 主菜单
     */
    public void MainMenu(){
        while(loop){
            System.out.println("===========满汉楼===========");
            System.out.println("\t\t 1 登入满汉楼");
            System.out.println("\t\t 2 退出满汉楼");
            System.out.print("请输入你的选择: ");
            choice = Utility.readString(1);
            switch(choice){
                case "1" :
                    System.out.println("登入到满汉楼");
                    System.out.print("请输入员工号: ");
                    String empId = Utility.readString(20);
                    System.out.print("请输入密码: ");
                    String pwd = Utility.readString(20);
                    Employee emp = employeeService.getEmployeeEmpIdAndPwd(empId, pwd);
                    if(emp != null){
                        System.out.println("========="+emp.getName()+" 登入成功===========");
                        SecondMenu();
                    }else{
                        System.out.println("===========登入失败===========");
                    }
                    break;
                case "2":
                    System.out.println("退出满汉楼系统~");
                    loop = false;
                    break;
                default:
                    System.out.println("输入错误!");

            }
        }
    }

    /**
     * 二级菜单
     */
    public void SecondMenu(){
        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 0 退出满汉楼(二级菜单)");
            System.out.print("请输入你的选择: ");
            choice = Utility.readString(1);
            switch (choice){
                case "1":
                    showMHLTable(); // 显示餐桌状态
                    break;
                case "2":
                    dueToTheTable(); // 预定餐桌
                    break;
                case "3":
                    showAllMenu(); // 显示所有菜品
                    break;
                case "4":
                    OrderingService(); // 点餐服务
                    break;
                case "5":
                    watchBill(); // 查看账单
                    break;
                case "6":
                    payBill();
                    break;
                case "0":
                    System.out.println("退出满汉楼(二级菜单)~");
                    return;
                default:
                    System.out.println("输入错误!");
            }
        }
    }

    /**
     * 显示餐桌状态
     */
    public void showMHLTable(){
        System.out.println("===========显示餐桌状态===========");
        for (MHLTable mhlTable :mhlTableService.tableMessage()
        ) {
            System.out.println("\t\t桌号: " + mhlTable.getId() + " 餐桌状态: " +mhlTable.getState());
        }
        System.out.println();
    }

    /**
     * 预定餐桌
     */
    public void dueToTheTable(){
        System.out.println("===========预定餐桌===========");
        System.out.print("请选择要预定餐桌的编号(-1 退出): ");
        int tableId = Utility.readInt();
        if(tableId == -1) {
            System.out.println("退出预定餐桌");
            return;
        }else if(!mhlTableService.IsOrderTable(tableId)){
            System.out.println("已经被预定或者无该桌号,抱歉");
            return;
        }
        System.out.print("确定是否预定(Y/N):");
        String judge = Utility.readString(1);
        if(judge.toLowerCase().equals("n")){
            System.out.println("退出预定餐桌");
            return;
        }else if(!(judge.toLowerCase().equals("y"))){
            System.out.println("输入错误!");
            return;
        }
        System.out.print("预定人姓名: ");
        String orderName = Utility.readString(32);
        System.out.print("预定人电话: ");
        String orderTel = Utility.readString(20);
        if(mhlTableService.updateMHLTable(tableId,orderName,orderTel)){
            System.out.println("===========预定成功===========");
        }else{
            System.out.println("===========预定失败===========");
        }
    }

    /**
     *  显示所有菜品
     */
    public void showAllMenu(){
        System.out.println("===========显示所有菜品===========");
        System.out.println("菜单编号  菜品名       类别     价格");
        for (com.Al_tair.mhlProject.domain.Menu menu : menuService.menuMessage()
        ) {
            System.out.println(menu);
        }
        System.out.println();
    }

    /**
     * 点餐服务
     */
    public void OrderingService(){
        System.out.println("===========点餐服务===========");
        System.out.print("请选择点餐的桌号(-1退出): ");
        int tableId = Utility.readInt();
        if(tableId == -1){
            System.out.println("===========取消点餐===========");
            return;
        }
        // 验证餐桌号
        MHLTable mhlTable = mhlTableService.tableSingleMessage(tableId);
        if(mhlTable == null){
            System.out.print("你输入的餐桌号错误!");
            return;
        }

        System.out.print("请选择点餐的菜品号(-1退出): ");
        int menuId = Utility.readInt();
        if(menuId == -1){
            System.out.println("===========取消点餐===========");
            return;
        }
        // 验证菜品编号是否存在
        com.Al_tair.mhlProject.domain.Menu menu = menuService.MenuSingleMessage(menuId);
        if(menu == null){
            System.out.print("你输入的菜品编号错误! ");
            return;
        }

        System.out.print("请选择点餐的数量(-1退出): " );
        int menuNum = Utility.readInt();
        if(menuNum == -1){
            System.out.println("===========取消点餐===========");
            return;
        }

        // 生成账单
        if(billService.orderMenu(menuId, menuNum, tableId)){
            System.out.println("===========点餐成功!==========");
        }
    }

    /**
     * 查看账单
     */
     public void watchBill(){
         System.out.println("===========查看账单==========");
         System.out.print("请问你要查看的账单的桌号(-1退出): ");
         int tableId = Utility.readInt();
         if(tableId == -1){
             System.out.println("===========退出查看账单==========");
             return;
         }
         List<Bill> bills = billService.watchAllBill(tableId);
         System.out.println(bills);
         bills = billService.watchBill(tableId);
         double priceSum = 0.0;
         for (Bill bill: bills
              ) {
             priceSum += bill.getMoney();
         }
         System.out.println("\t桌号:" + tableId + "\t\t总金额: " + priceSum);
     }

    /**
     * 结账
     */
    public void payBill(){
        System.out.println("===========结账==========");
        System.out.print("请选择要结账的餐桌编号(-1退出):");
        int tableId = Utility.readInt();
        if(tableId == -1){
            System.out.println("===========取消结账==========");
            return;
        }
        MHLTable mhlTable = mhlTableService.tableSingleMessage(tableId);
        if(mhlTable == null){
            System.out.println("===========结账餐桌不存在==========");
            return;
        }
        boolean hasPayBill = billService.hasPayBill(tableId);
        if(!hasPayBill){
            System.out.println("===========该餐桌无需结账==========");
            return;
        }

        System.out.print("请选择要结账的方式(现金/支付宝/微信):");
        String payMode = Utility.readString(10,""); // 如果回车,就是默认返回""
        if("".equals(payMode)){
            System.out.println("===========取消结账==========");
            return;
        }

        System.out.print("确定是否预定(Y/N):");
        String judge = Utility.readString(1);
        if(judge.toLowerCase().equals("n")){
            System.out.println("===========取消结账==========");
            return;
        }else if(!(judge.toLowerCase().equals("y"))){
            System.out.println("输入错误!");
            return;
        }
        if(billService.payBill(tableId, payMode)){
            System.out.println("===========完成结账==========");
        }else{
            System.out.println("===========结账失败==========");
        }
    }
}

操作数据库(Dao层)

BasicDao层
package com.Al_tair.mhlProject.dao;

import com.Al_tair.connectMySql.dao_.utils.JDBCUtilsByDruid;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class BasicDao<T> {
    private QueryRunner qr = new QueryRunner();

    // dml操作语句
    public int DmlUpdate(String sql,Object...params){
        Connection connection = null;

        try {
            connection = JDBCUtilsByDruid.getConnection();
            return qr.update(connection,sql,params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JDBCUtilsByDruid.closeConnection(connection);
        }
    }

    // 查询语句:返回集合(表)
    public List<T> SelectMultiLine(String sql, Class<T> cls, Object...params){
        Connection connection = null;
        try {
            connection = JDBCUtilsByDruid.getConnection();
            return qr.query(connection,sql,new BeanListHandler<T>(cls),params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JDBCUtilsByDruid.closeConnection(connection);
        }
    }

    // 查询语句:返回单行数据
    public T SelectSingleLine(String sql, Class<T> cls, Object...params){
        Connection connection = null;
        try {
            connection = JDBCUtilsByDruid.getConnection();
            return qr.query(connection,sql,new BeanHandler<T>(cls),params);
        } catch (SQLException e) {
            System.out.println("查询不到该数据");;
            return null;
        }finally {
            JDBCUtilsByDruid.closeConnection(connection);
        }
    }

    // 查询语句:返回某行某列数据
    public Object SelectSingleLine(String sql, Object...params){
        Connection connection = null;
        try {
            connection = JDBCUtilsByDruid.getConnection();
            return qr.query(connection,sql,new ScalarHandler(),params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JDBCUtilsByDruid.closeConnection(connection);
        }
    }
}
Dao层
public class BillDao extends BasicDao<Bill>{}

public class EmployeeDao extends BasicDao<Employee>{}

public class MenuDao extends BasicDao<Menu>{}

public class MHLTableDao extends BasicDao<MHLTable>{}
数据库数据
# 解决中文乱码问题 https://blog.csdn.net/haduwi/article/details/107134679
# show variables like 'character_set_%' 
# 检查character_set_server和character_set_client 是否为utf8
CREATE TABLE employee(
			id INT PRIMARY KEY auto_increment,
			empId VARCHAR(50) NOT NULL DEFAULT '',
			pwd CHAR(32) NOT NULL DEFAULT '',
			`name` VARCHAR(32) NOT NULL DEFAULT '',
			job VARCHAR(32) NOT null DEFAULT ''
)CHARACTER SET utf8;
INSERT INTO employee VALUES(NULL,'1932332101',MD5('123456'),'郭靖','经理');
INSERT INTO employee VALUES(NULL,'1932332102',MD5('123789'),'杨过','收银员');
INSERT INTO employee VALUES(NULL,'1932332103',MD5('456789'),'欧阳锋','服务员');
INSERT INTO employee VALUES(NULL,'1932332104',MD5('789789'),'黄蓉','经理');
SELECT *FROM employee;

CREATE TABLE MHLTable(
      		id INT PRIMARY KEY auto_increment,
			state VARCHAR(10) NOT NULL DEFAULT '',
			orderName CHAR(32) NOT NULL DEFAULT '',
			orderTel VARCHAR(20) NOT NULL DEFAULT ''
)CHARACTER SET utf8;
INSERT INTO MHLTable VALUES(NULL,'empty','','');
INSERT INTO MHLTable VALUES(NULL,'empty','','');
INSERT INTO MHLTable VALUES(NULL,'empty','','');
SELECT *FROM MHLTable;


CREATE TABLE menu(
      		id INT PRIMARY KEY auto_increment,
			`name` CHAR(32) NOT NULL DEFAULT '',
			type VARCHAR(20) NOT NULL DEFAULT '',
			price DOUBLE NOT NULL DEFAULT 0.0
)CHARACTER SET utf8;
INSERT INTO menu VALUES(NULL,'麻辣香锅','主食',20);
INSERT INTO menu VALUES(NULL,'土豆丝','热食',10);
INSERT INTO menu VALUES(NULL,'凉拌豆腐','冷食',8);
INSERT INTO menu VALUES(NULL,'炒鸡蛋','热食',10);
INSERT INTO menu VALUES(NULL,'酸菜鱼','热食',40);
INSERT INTO menu VALUES(NULL,'糖醋排骨','热食',30);
INSERT INTO menu VALUES(NULL,'甲鱼汤','汤',60);
INSERT INTO menu VALUES(NULL,'鸽子汤','汤',50);
INSERT INTO menu VALUES(NULL,'冰淇凌','小吃',10);
INSERT INTO menu VALUES(NULL,'银丝卷','甜食',15);
SELECT *FROM menu;

CREATE TABLE bill(
		id INT PRIMARY KEY auto_increment,
		billId VARCHAR(50) NOT NULL DEFAULT '',
		menuId int NOT NULL DEFAULT 0,
		menuNum int NOT NULL DEFAULT 0,
		money DOUBLE NOT NULL DEFAULT 0.0,
		tableId int NOT NULL DEFAULT 0,
		billDate datetime NOT NULL,
		billState VARCHAR(10) NOT NULL DEFAULT ''
)CHARACTER SET utf8;
SELECT *FROM bill;

实体类(domain)

bill类

image-20220413130848694

Employee类

image-20220413130913047

Menu类

image-20220413130943364

MHLTable类

image-20220413130958702

事务层(service)

MenuService

public class MenuService {
    // 定义MenuDao对象
    private MenuDao menuDao = new MenuDao();


    // 返回所有所有菜品
    public List<Menu> menuMessage(){
        String sql = "select *from Menu";
        return menuDao.SelectMultiLine(sql,Menu.class);
    }

    // 返回预定餐桌好对应的餐桌信息
    public Menu MenuSingleMessage(int id){
        String sql = "select *from Menu where id = ?";
        return  menuDao.SelectSingleLine(sql, Menu.class, id);
    }

    // 返回账单金额费用
    public Menu getPriceById(int id){
        String sql = "select *from menu where id = ?";
        return menuDao.SelectSingleLine(sql,Menu.class,id);
    }
}

BillService

public class BillService {
    // 创建BillDao对象
    private BillDao billDao = new BillDao();
    // 定义MenuService属性
    private MenuService menuService = new MenuService();
    // 定义MHLTable属性
    private MHLTableService mhlTableService = new MHLTableService();

    // 生成账单
    public boolean orderMenu(int menuId,int menuNum,int tableId){
        // 用UUID生成随机字符串
        String billId = UUID.randomUUID().toString();
        String sql = "insert into bill values(null,?,?,?,?,?,now(),'未结账')";
        // 计算账单的金额
        double price = menuService.getPriceById(menuId).getPrice() * menuNum;
        int row = billDao.DmlUpdate(sql, billId, menuId, menuNum, price, tableId);
        if(row <= 0) return false;
        return mhlTableService.updateMHLTableState(tableId, "eating");
    }

	// 查看所有账单根据桌号
    public List<Bill> watchAllBill(int tableId){
        String sql = "select *from bill where tableId = ?";
        return billDao.SelectMultiLine(sql,Bill.class,tableId);
    }

    // 查看账单根据桌号
    public List<Bill> watchBill(int tableId){
        String sql = "select *from bill where tableId = ? and billState = '未结账'";
        return billDao.SelectMultiLine(sql,Bill.class,tableId);
    }

    // 查看某个餐桌是否有未结账的账单
    public boolean hasPayBill(int tableId){
        String sql = "select *from bill where tableId = ? and billState = '未结账' limit 0,1";
        Bill bill = billDao.SelectSingleLine(sql, Bill.class, tableId);
        return bill != null;
    }

    // 完成结账 payMode:微信/支付宝/赊账
    public boolean payBill(int tableId,String payMode){
        // 修改bill表
        String sql = "update bill set billState = ? where tableId = ? and billState = '未结账'";
        int row = billDao.DmlUpdate(sql, payMode, tableId);
        if(row <= 0) return false;

        // 修改MHLTable表
        if(!mhlTableService.initState(tableId)){
            return false;
        }
        return true;
    }
}

MHLTableService

public class MHLTableService {
    // 定义MHLTableDao对象
    private MHLTableDao mhlTableDao= new MHLTableDao();

    // 返回所有餐桌信息
    public List<MHLTable> tableMessage(){
        String sql = "select *from MHLTable";
        return mhlTableDao.SelectMultiLine(sql,MHLTable.class);
    }

    // 返回是否能预定餐桌号
    public boolean IsOrderTable(int id){
        String sql = "select *from MHLTable where id = ?";
        MHLTable mhlTable = mhlTableDao.SelectSingleLine(sql, MHLTable.class, id);
        if(mhlTable == null || !mhlTable.getState().equals("empty")){
            return false;
        }
        return true;
    }

    // 返回预定餐桌好对应的餐桌信息
    public MHLTable tableSingleMessage(int id){
        String sql = "select *from MHLTable where id = ?";
        return  mhlTableDao.SelectSingleLine(sql, MHLTable.class, id);
    }

    // 存入数据(姓名和电话)到数据库 MHLTable表
    public boolean updateMHLTable(int id,String orderName,String orderTel){
        String sql = "update MHLTable set state = 'isOrdered',orderName = ?, orderTel = ? where id = ?";
        int row = mhlTableDao.DmlUpdate(sql, orderName, orderTel, id);
        return row > 0?true:false;
    }

    // 更新餐桌状态的方法
    public boolean updateMHLTableState(int id,String state){
        String sql = "update MHLTable set state = ? where id = ?";
        int row = mhlTableDao.DmlUpdate(sql, state, id);
        return row > 0;
    }

    // 修改餐桌表的状态 eating -> empty ; 清空 orderName,orderTel
    public boolean initState(int id){
        String sql = "update MHLTable set state = 'empty',orderName = '',orderTel = '' where id = ?";
        int row = mhlTableDao.DmlUpdate(sql, id);
        return row > 0;
    }
}

EmployeeService

public class EmployeeService {
    // 用EmployeeDao来实现
    private EmployeeDao employeeDao = new EmployeeDao();

    //根据empId和pwd返回一个员工表,如果查询不到则返回null
    public Employee getEmployeeEmpIdAndPwd(String empId,String pwd){
        String sql = "select *from employee where empId = ? and pwd = md5(?)";
        return employeeDao.SelectSingleLine(sql, Employee.class, empId, pwd);
    }

}

启动类(Main)

public class Main {
    public static void main(String[] args) {
        new Menu().MainMenu();
    }
}

展现效果

员工登录

image-20220413131841137

菜单

image-20220413131934727

显示餐桌状态

image-20220413132001456

预定餐桌

image-20220413132107721

显示所有菜单

image-20220413132135629

点餐服务

image-20220413132253655

查看账单

image-20220413132502835

结账

image-20220413132646934

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Al_tair

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值