首页 > 其他 > 详细

小郡肝火锅点餐系统——部分代码实现

时间:2019-05-29 17:42:36      阅读:180      评论:0      收藏:0      [点我收藏+]

数据库代码:

create database d_tastyfood;
use d_tastyfood;
/*菜单*/
create table t_food(
     id int primary key auto_increment,
     foodname varchar(20),
     foodprice double,
     img varchar(100),
     des varchar(100),
     t_foodtype_id int
);
/*菜种类*/
create table t_foodtype(
     id int primary key auto_increment,
     typename varchar(20)
);
/*订单*/
create table t_foodorder(
     t_food_id int,
     foodcount int,
     datatime datetime,
     totalprice double
);


alter table t_food add constraint FK_ID 
foreign key(t_foodtype_id) references t_foodtype(id);
alter table  t_foodorder add constraint t_foodorder_t_food_id 
foreign key (t_food_id) references t_food(id);

Java

JdbcUtils.java

package cn.itcast.utils;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 封装常用的操作
 * @author home
 *
 */
public class JdbcUtils {

    // 初始化连接池
    private static DataSource dataSource;
    static {
        dataSource = new ComboPooledDataSource();
    }
    
    public static DataSource getDataSource() {
        return dataSource;
    }
    
    /**
     * 创建DbUtils常用工具类对象
     */
    public static QueryRunner getQuerrRunner() {
        return new QueryRunner(dataSource);
    }
}

 

FoodTypeServlet.java

package cn.itcast.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itcast.entity.FoodType;
import cn.itcast.factory.BeanFactory;
import cn.itcast.service.IFoodTypeService;

/**
 * 4. 菜系管理Servlet开发
 *
 * a. 添加菜系
 * b. 菜系列表展示
 * c. 进入更新页面
 * d. 删除
 * e. 更新
 *
 * @author home
 *
 */
public class FoodTypeServlet extends HttpServlet {
    
    // 调用的菜系Service
    private IFoodTypeService foodTypeService = BeanFactory.getInstance("foodTypeService",IFoodTypeService.class);
    // 跳转资源
    private Object uri;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        
        // 获取操作的类型
        String method = request.getParameter("method");
        // 判断
        if ("addFoodType".equals(method)) {
            // 添加
            addFoodType(request, response);
        }

        else if ("list".equals(method)) {
            // 列表展示
            list(request, response);
        }
        
        else if ("viewUpdate".equals(method)) {
            // 进入更新页面
            viewUpdate(request, response);
        }
        
        else if ("delete".equals(method)) {
            // 删除
            delete(request, response);
        }
        
        else if ("update".equals(method)) {
            // 更新
            update(request, response);
        }
    }
  /**
     * 跳转的方法
     */
    private void goTo(HttpServletRequest request, HttpServletResponse response, Object uri)
            throws ServletException, IOException {
        if (uri instanceof RequestDispatcher){
            ((RequestDispatcher)uri).forward(request, response);
        } else if (uri instanceof String) {
            response.sendRedirect(request.getContextPath() + uri);
        }
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doGet(request, response);
    }

}

Html代码

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    
<title>火锅点餐平台</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="detail/style/js/jquery.js"></script>
<script type="text/javascript" src="detail/style/js/page_common.js"></script>
<link href="detail/style/css/common_style_blue.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="detail/style/css/index_1.css" />
    <style type="text/css">
    * {
        margin: 0px;
        padding: 0px
    }
    #dish_2 a{
        text-decoration:none;
        font-size:36px;
        color:#000;
    }
    #dish_2 ul { 
        list-style:none;
    } 
    #dish_2 li{
        background:url(style/images/img/btn.gif);
        width:164px;
        height:47px;
        text-align:center;
        padding-top:5px;
    }
    </style>
</head>
<body style="text-align: center">
    <!--外部的大层-->
    <div class="index_all" style="text-align:center;">
        <!--上面的背景层-->
        <div>
            <img src="detail/style/images/flower.gif"  height="230"/>
        </div>
            <!--放桌子的层-->
            <div id="center_bottom">
                <ul style=" display:inline-table">
                        <li>
                            <a href="detail/caidan.html">
                                菜单&nbsp;
                            </a>
                        </li>
                </ul>
            </div>
        <!--下面的背景层-->
        <div>
            <img src="detail/style/images/flower.gif"  height="230"/>
        </div>
    </div>
</body>
</html>

 

小郡肝火锅点餐系统——部分代码实现

原文:https://www.cnblogs.com/lj520fj/p/10944842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!