简介
本项目采用WEB+Servlet+HTML+CSS+JS实现,模拟收银台实现基本的操作。
重要知识点
1、Java类集的使用
2、Servlet的使用
3、前端部分知识的简单运用。
4、数据库的表的设计,尤其是订单和订单项之间的设计
5、JDBC编程
核心需求
实现如下的操作:
1、上架商品
2、浏览商品
3、更新商品信息
4、购买商品
5、浏览订单
数据库设计
商品表(goods)
账户表
订单表(order)
订单项表(order_item)
创建数据库代码:注意为了避免价格会出现小数,在存入数据库的同时,需要转化为整数
-- 数据库
drop database if exists `cash`;
create database if not exists `cash` character set utf8;
-- 使用数据库
use `cash`;
-- 帐号
drop table if exists `account`;
create table if not exists `account`
(
id int primary key auto_increment comment '帐号编号',
username varchar(12) not null comment '帐号',
password varchar(128) not null comment '密码'
);
-- 商品信息
drop table if exists `goods`;
create table if not exists `goods`
(
id int primary key auto_increment comment '商品编号',
name varchar(128) not null comment '商品名称',
introduce varchar(256) default '暂无' not null comment '商品简介',
stock int not null comment '商品库存',
unit varchar(12) not null comment '库存单位',
price int not null comment '商品价格,单位:分',
discount int default 100 not null comment '商品折扣,[0,100]'
);
-- 订单
drop table if exists `order`;
create table if not exists `order`
(
id varchar(32) primary key comment '订单编号',
account_id int not null comment '帐号编号',
account_name varchar(12) not null comment '帐号',
create_time datetime not null comment '创建时间',
finish_time datetime default null comment '完成时间',
actual_amount int not null comment '实际金额,单位:分',
total_money int not null comment '总金额,单位:分',
order_status int not null comment '支付状态 1 待支付 2 完成'
);
-- 订单项
drop table if exists `order_item`;
create table if not exists `order_item`
(
id int primary key auto_increment comment '订单条目编号',
order_id varchar(32) not null comment '订单编号',
goods_id int not null comment '商品编号',
goods_name varchar(128) not null comment '商品名称',
goods_introduce varchar(256) default '暂无' not null comment '商品简介',
goods_num int not null comment '商品数量',
goods_unit varchar(12) not null comment '库存单位',
goods_price int not null comment '商品价格,单位:分',
goods_discount int default 100 not null comment '商品折扣,[0,100]'
);
功能展示
功能菜单展示
上架商品
浏览商品
更新商品信息
浏览订单
购买商品
项目整体框架
@WebServlet注 释配置Servlet
Servlet配置有两种方式:
1、Servlet类上使用@WebServlet注解进行配置
2、web.xml文件中配置
客户端和服务器通信方式-Servlet
Servlet 是服务器端程序,主要用来交互式地浏览和修改数据,生成动态web内容。web服务器接收到客户端的Servlet 请求后,如果检查到已经装载并创建了该Servlet的实例对象,则会创建一个用于封装HTTP请求消息的HttpServletRequest 对象和一个代表Http响应消息的 HttpServletResponse 对象,然后调用Servlet的service()方法,将请求和响应对象作为参数传递进去,这样客户端通过 HttpServletRequest 对象将请求发送给服务器,服务器通过 HttpServletResponse 对象将响应传递给客户端,达到通信的目的。
项目目录结构
项目的搭建
- 在IDEA中,点击 File -> New -> Module,选择Maven -> Next。
- 在GroupId和Artifact