Java Web-订餐系统分享项目 jsp+servlet+java+MySQL+带数据库语法

分享一款使用jsp、servlet和MySQL技术实现的订餐系统项目,包括数据库语法和session管理。提供源码下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

订餐系统架构

在这里插入图片描述
下载源码链接:https://pan.baidu.com/s/1vldCXtOONd3HfY5qBjiTJg
提取码:mf2s

代码实现

package com.orderonline.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * @author yangxiaoqiang
 * 
 * */
/**数据库连接类*/
public class DBUtil {

	private static final String CLASSNAME = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/food_db?characterEncoding=utf-8&serverTimezone=GMT";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "你的数据库密码";

	static {
		try {
			Class.forName(CLASSNAME);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}

package com.orderonline.info.user;

import com.orderonline.pojo.TBOrder;
import com.orderonline.pojo.TbCate;
import com.orderonline.pojo.TbUser;
import com.orderonline.pojo.Tborder_detail;
/**
 * @author yangxiaoqiang
 * 
 * */
/**操作接口--查询和检查用户信息是否存在*/
public interface User_Cart_Imp {
	/**通过user_id找到用户信息-----针对页面details.jsp and shopCart.jsp**/
	public TbUser userInfo(Integer user_id);
	/**通过cart_id找到该商品信息-----针对页面details.jsp  and shopCart.jsp*/
	public TbCate cartInfo(Integer cart_id);
	
	
	/**通过order_id找到用户是否存相同订单id*/
	public boolean ordercheck(Integer order_id);
	
	/**通过order_id找到用户是否存相同订单id*/
	public TBOrder order(Integer order_id);
	
	/**查出用户下的所有下单信息*/
	public TBOrder orderinfo(Integer user_id);
	
	
	
	/**订单信息表*/
	public int InsertOrder(TBOrder Order);
	
	/**购物车信息添加——订单详细信息表*/
	public int InsertTborder_detail(Integer order_id,Tborder_detail detail);
}

package com.orderonline.info.user;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TBOrder;
import com.orderonline.pojo.TbCate;
import com.orderonline.pojo.TbUser;
import com.orderonline.pojo.Tborder_detail;

/**
 * @author yangxiaoqiang
 * 
 * */
/**实现操作类--查询和检查用户信息是否存在*/
public class user_cart_info implements User_Cart_Imp {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	@Override
	public TbUser userInfo(Integer user_id) {
		TbUser user = null;
		String sql = "select * from tb_user where user_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, user_id);
			rs = pstmt.executeQuery();
			if (rs.next()) {// 当登录成功
				user = new TbUser();
				user.setUser_id(rs.getInt("user_id"));
				user.setUser_name(rs.getString("user_name"));
				user.setCh_name(rs.getString("ch_name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return user;
	}

	@Override
	public TbCate cartInfo(Integer cart_id) {
		TbCate cate=new TbCate();
		String sql="select * from tb_cate where cate_id=? ";
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, cart_id);
			// 执行SQL语句
			rs = pstmt.executeQuery();
			while(rs.next()) {
				cate = new TbCate();
				cate.setCate_id(rs.getInt("cate_id"));
				cate.setCate_name(rs.getString("cate_name"));
				cate.setCur_price(rs.getFloat("cur_price"));
				cate.setDescript(rs.getString("descript"));
				cate.setImg_path(rs.getString("img_path"));
				cate.setOri_price(rs.getFloat("ori_price"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return cate;
	}

	@Override
	public boolean ordercheck(Integer order_id) {
		String sql = "select * from tb_order where order_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, order_id);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				return true;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return false;
	}
	
	
	
	@Override
	public TBOrder orderinfo(Integer user_id) {
		TBOrder Order = new TBOrder() ;
		String sql = "select * from tb_order where user_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, user_id);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				Order.setOrder_id(rs.getInt("order_id"));
				Order.setAddress(rs.getString("address"));
				Order.setCh_name(rs.getString("ch_name"));
				Order.setEmail(rs.getString("email"));
				Order.setMobile(rs.getString("mobile"));
				Order.setPayType(rs.getString("payType"));
				Order.setPhone(rs.getString("phone"));
				Order.setPostalcode(rs.getString("postalcode"));
				Order.setPostscript(rs.getString("postscript"));
				Order.setSendType(rs.getString("sendType"));
				Order.setUser_id(rs.getInt("user_id"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return Order;
	}
	
	
		//测试成功!
	public static void main(String[] args){
		//System.out.println(new user_cart_info().ordercheck(1));
		//System.out.println(new user_cart_info().userInfo(1));
		//System.out.println(new user_cart_info().cartInfo(1));
		//System.out.println(new user_cart_info().orderinfo(1));
	/*	TBOrder Order=new TBOrder();
		Order.setAddress("sadf");
		Order.setCh_name("556300");
		Order.setEmail("556300");
		Order.setMobile("556300");
		Order.setOrder_id(456);
		Order.setPayType("d");
		Order.setPhone("556300");
		Order.setPostalcode("556300");
		Order.setPostscript("不好");
		Order.setSendType("s");
		Order.setUser_id(1);
		int i=new user_cart_info().InsertOrder(Order);
		System.out.println(i);
		*/
		/*Tborder_detail detail=new Tborder_detail();
		detail.setCate_id(1);
		detail.setCate_name("fas");
		detail.setCOUNT(5);
		detail.setDetail_id(1);
		detail.setMoney(22);
		detail.setPrice(55);
		detail.setOrder_id(1);
		
		int i=new user_cart_info().InsertTborder_detail(1, detail);
		System.out.println(i);
		*/
	}

	

	@Override
	public int InsertTborder_detail(Integer order_id, Tborder_detail detail) {
		String sql = "insert into tb_order_detail values (?,?,?,?,?,?,?) ";
		conn = DBUtil.getConnection();
		int count = 0; // 受影响的行数
		try {
			pstmt = (PreparedStatement) conn.prepareStatement(sql);
			// 设置参数
			pstmt.setObject(1,0 );
			pstmt.setObject(2,order_id );
			pstmt.setObject(3, detail.getCate_id());
			pstmt.setObject(4, detail.getCate_name());
			pstmt.setObject(5, detail.getPrice());
			pstmt.setObject(6, detail.getCOUNT());
			pstmt.setObject(7, detail.getMoney());
			count = pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return count;
	}

	@Override
	public int InsertOrder(TBOrder Order) {
		String sql = "insert into tb_order VALUES(?,?,?,?,?,?,?,?,?,?,?) ";
		conn = DBUtil.getConnection();
		int count = 0; // 受影响的行数
		try {
			pstmt = (PreparedStatement) conn.prepareStatement(sql);
			// 设置参数
			pstmt.setObject(1,Order.getOrder_id() );
			pstmt.setObject(2,Order.getUser_id() );
			pstmt.setObject(3, Order.getCh_name());
			pstmt.setObject(4, Order.getAddress());
			pstmt.setObject(5, Order.getPostalcode());
			pstmt.setObject(6, Order.getPhone());
			pstmt.setObject(7, Order.getMobile());
			pstmt.setObject(8, Order.getEmail());
			pstmt.setObject(9, Order.getSendType());
			pstmt.setObject(10, Order.getPayType());
			pstmt.setObject(11, Order.getPostscript());
			count = pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return count;
	}

	@Override
	public TBOrder order(Integer order_id) {
		TBOrder Order = null ;
		String sql = "select * from tb_order where order_id=?  ;";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, order_id);
			rs = pstmt.executeQuery();
			if (rs.next()) {// 当登录成功
				Order = new TBOrder();
				Order.setCh_name(rs.getString("ch_name"));
				Order.setAddress(rs.getString("address"));
				Order.setPhone(rs.getString("phone"));
				Order.setEmail(rs.getString("email"));
				Order.setOrder_id(rs.getInt("order_id"));
				Order.setMobile(rs.getString("mobile"));
				Order.setPostscript(rs.getString("postscript"));
				Order.setSendType(rs.getString("sendType"));
				Order.setPostalcode(rs.getString("postalcode"));
				Order.setPayType(rs.getString("payType"));;
				
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return Order;
	}
	
	
	
}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/***商品信息类*/
public class TbCate {
	
	private Integer cate_id;
	private String cate_name;
	private Float ori_price;
	private Float cur_price;
	private String img_path;
	private String descript;
	public Integer getCate_id() {
		return cate_id;
	}
	public void setCate_id(Integer cate_id) {
		this.cate_id = cate_id;
	}
	public String getCate_name() {
		return cate_name;
	}
	public void setCate_name(String cate_name) {
		this.cate_name = cate_name;
	}
	public Float getOri_price() {
		return ori_price;
	}
	public void setOri_price(Float ori_price) {
		this.ori_price = ori_price;
	}
	public Float getCur_price() {
		return cur_price;
	}
	public void setCur_price(Float cur_price) {
		this.cur_price = cur_price;
	}
	public String getImg_path() {
		return img_path;
	}
	public void setImg_path(String img_path) {
		this.img_path = img_path;
	}
	public String getDescript() {
		return descript;
	}
	public void setDescript(String descript) {
		this.descript = descript;
	}
	public TbCate(Integer cate_id, String cate_name, Float ori_price, Float cur_price, String img_path,
			String descript) {
		this.cate_id = cate_id;
		this.cate_name = cate_name;
		this.ori_price = ori_price;
		this.cur_price = cur_price;
		this.img_path = img_path;
		this.descript = descript;
	}
	
	public TbCate() {
	}
	@Override
	public String toString() {
		return "TbCate [cate_id=" + cate_id + ", cate_name=" + cate_name + ", ori_price=" + ori_price + ", cur_price="
				+ cur_price + ", img_path=" + img_path + ", descript=" + descript + "]";
	}
	

}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**订单详细信息表--类*/
public class Tborder_detail {
	 private Integer detail_id ; // '订单详细id',
	 private Integer  order_id ;// '订单id' ,
	 private Integer   cate_id  ;//'商品id',
	 private String  cate_name  ; //'商品名称',
	 private double  price   ;//'价格',
	 private Integer  COUNT ; //'数量',
	 private double  money   ;// '金额'
	public Integer getDetail_id() {
		return detail_id;
	}
	public void setDetail_id(Integer detail_id) {
		this.detail_id = detail_id;
	}
	public Integer getOrder_id() {
		return order_id;
	}
	public void setOrder_id(Integer order_id) {
		this.order_id = order_id;
	}
	public Integer getCate_id() {
		return cate_id;
	}
	public void setCate_id(Integer cate_id) {
		this.cate_id = cate_id;
	}
	public String getCate_name() {
		return cate_name;
	}
	public void setCate_name(String cate_name) {
		this.cate_name = cate_name;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public Integer getCOUNT() {
		return COUNT;
	}
	public void setCOUNT(Integer cOUNT) {
		COUNT = cOUNT;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	public Tborder_detail() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Tborder_detail(Integer detail_id, Integer order_id, Integer cate_id,
			String cate_name, Float price, Integer cOUNT, Float money) {
		super();
		this.detail_id = detail_id;
		this.order_id = order_id;
		this.cate_id = cate_id;
		this.cate_name = cate_name;
		this.price = price;
		COUNT = cOUNT;
		this.money = money;
	}
	@Override
	public String toString() {
		return "Tborder_detail [detail_id=" + detail_id + ", order_id="
				+ order_id + ", cate_id=" + cate_id + ", cate_name="
				+ cate_name + ", price=" + price + ", COUNT=" + COUNT
				+ ", money=" + money + "]";
	}
	 
	 
}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**订单类*/
public class TBOrder {
	private Integer order_id; // '订单id',
    private Integer user_id ;//'用户id',
	private String  ch_name ; // '订餐人',
	private String  address ;// '送货地址',
	private String  postalcode ;// '邮政编码',
	private String  phone   ; //'联系电话',				
	private String   mobile   ; // '移动电话',
	private String  email   ; //'电子邮件',
	private String  sendType ; // '配送方式',
	private String  payType  ; // '支付方式',
	private String  postscript ;  //'订单附言'
	public Integer getOrder_id() {
		return order_id;
	}
	public void setOrder_id(Integer order_id) {
		this.order_id = order_id;
	}
	public Integer getUser_id() {
		return user_id;
	}
	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}
	public String getCh_name() {
		return ch_name;
	}
	public void setCh_name(String ch_name) {
		this.ch_name = ch_name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPostalcode() {
		return postalcode;
	}
	public void setPostalcode(String postalcode) {
		this.postalcode = postalcode;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getSendType() {
		return sendType;
	}
	public void setSendType(String sendType) {
		this.sendType = sendType;
	}
	public String getPayType() {
		return payType;
	}
	public void setPayType(String payType) {
		this.payType = payType;
	}
	public String getPostscript() {
		return postscript;
	}
	public void setPostscript(String postscript) {
		this.postscript = postscript;
	}
	public TBOrder() {
		
	}
	public TBOrder(Integer order_id, Integer user_id, String ch_name,
			String address, String postalcode, String phone, String mobile,
			String email, String sendType, String payType, String postscript) {
		super();
		this.order_id = order_id;
		this.user_id = user_id;
		this.ch_name = ch_name;
		this.address = address;
		this.postalcode = postalcode;
		this.phone = phone;
		this.mobile = mobile;
		this.email = email;
		this.sendType = sendType;
		this.payType = payType;
		this.postscript = postscript;
	}
	@Override
	public String toString() {
		return "TBOrder [order_id=" + order_id + ", user_id=" + user_id
				+ ", ch_name=" + ch_name + ", address=" + address
				+ ", postalcode=" + postalcode + ", phone=" + phone
				+ ", mobile=" + mobile + ", email=" + email + ", sendType="
				+ sendType + ", payType=" + payType + ", postscript="
				+ postscript + "]";
	}
	
	

}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**用户表信息类*/
public class TbUser {

	private Integer user_id; // 用户ID
	private String user_name; // 用户名称
	private String ch_name; // 真实姓名
	private String password; // 用户密码

	public Integer getUser_id() {
		return user_id;
	}

	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}

	public String getCh_name() {
		return ch_name;
	}

	public void setCh_name(String ch_name) {
		this.ch_name = ch_name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public TbUser(Integer user_id, String user_name, String ch_name, String password) {
		this.user_id = user_id;
		this.user_name = user_name;
		this.ch_name = ch_name;
		this.password = password;
	}

	public TbUser() {
	}

	@Override
	public String toString() {
		return "TbUser [user_id=" + user_id + ", user_name=" + user_name + ", ch_name=" + ch_name + ", password="
				+ password + "]";
	}

}

package com.orderonline.service.cate;

import java.util.List;

import com.orderonline.pojo.TbCate;

public interface TbCateService {
	
	public List<TbCate> cateList();

}

package com.orderonline.service.cate;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TbCate;

public class TbCateServiceImpl implements TbCateService {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	
	@Override
	public List<TbCate> cateList() {
		List<TbCate> list = new ArrayList<TbCate>();
		TbCate cate = null;
		String sql = "select * from tb_cate";
		
		conn = DBUtil.getConnection();
		
		try {
			pstmt = conn.prepareStatement(sql);
			// 执行SQL语句
			rs = pstmt.executeQuery();
			while(rs.next()) {
				cate = new TbCate();
				
				cate.setCate_id(rs.getInt("cate_id"));
				cate.setCate_name(rs.getString("cate_name"));
				cate.setCur_price(rs.getFloat("cur_price"));
				cate.setDescript(rs.getString("descript"));
				cate.setImg_path(rs.getString("img_path"));
				cate.setOri_price(rs.getFloat("ori_price"));
				list.add(cate);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	/*
	//测试两个商品一行
	public static void main(String[] args) {
		TbCateService tcs = new TbCateServiceImpl();
		Iterator<TbCate> it = tcs.cateList().iterator();
		// 3,4,5,6,7,8,9,10
		while(it.hasNext()) { // 判断迭代器里是否还有值存在
			TbCate t1 = it.next();
			System.out.print(t1.getCate_name() + "\t");
			//第二个商品
			if (it.hasNext()) {
				TbCate t2 = it.next();
				System.out.print(t2.getCate_name());
			}
			
			System.out.println("\n");
		}
		
		
	}*/

}

package com.orderonline.service.user;

import com.orderonline.pojo.TbUser;

public interface TbUserService {
	
	public TbUser userLogin(String user,String pass);

}

package com.orderonline.service.user;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TbUser;

public class TbUserServiceImpl implements TbUserService {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	
	@Override
	public TbUser us
智能网联汽车的安全员高级考试涉及多个方面的专业知识,包括但不限于自动驾驶技术原理、车辆传感器融合、网络安全防护以及法律法规等内容。以下是针对该主题的一些核心知识解析: ### 关于智能网联车安全员高级考试的核心内容 #### 1. 自动驾驶分级标准 国际自动机工程师学会(SAE International)定义了六个级别的自动驾驶等级,从L0到L5[^1]。其中,L3及以上级别需要安全员具备更高的应急处理能力。 #### 2. 车辆感知系统的组成与功能 智能网联车通常配备多种传感器,如激光雷达、毫米波雷达、摄像头和超声波传感器等。这些设备协同工作以实现环境感知、障碍物检测等功能[^2]。 #### 3. 数据通信与网络安全 智能网联车依赖V2X(Vehicle-to-Everything)技术进行数据交换,在此过程中需防范潜在的网络攻击风险,例如中间人攻击或恶意软件入侵[^3]。 #### 4. 法律法规要求 不同国家和地区对于无人驾驶测试及运营有着严格的规定,考生应熟悉当地交通法典中有关自动化驾驶部分的具体条款[^4]。 ```python # 示例代码:模拟简单决策逻辑 def decide_action(sensor_data): if sensor_data['obstacle'] and not sensor_data['emergency']: return 'slow_down' elif sensor_data['pedestrian_crossing']: return 'stop_and_yield' else: return 'continue_driving' example_input = {'obstacle': True, 'emergency': False, 'pedestrian_crossing': False} action = decide_action(example_input) print(f"Action to take: {action}") ``` 需要注意的是,“同学”作为特定平台上的学习资源名称,并不提供官方认证的标准答案集;建议通过正规渠道获取教材并参加培训课程来准备此类资格认证考试
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值