收银台项目详解

项目介绍

此项目主要基于HTTP协议实现,实现了最基本的收银台功能,使用Spring MVC框架,Mybatis,MySQL,HTML,CSS,JS等技术开发而成。

项目前端界面
在这里插入图片描述


后台界面在这里插入图片描述

项目功能

请添加图片描述

使用框架

请添加图片描述

业务逻辑

请添加图片描述

注册

  1. 通过form表单发起post请求 静态资源
  2. 验证逻辑 POST/register.do 动态资源
  • Controller 读取from表单提交的用户信息,做参数的合法性校验

  • Service 负责密码加密的工作

  • Mapper 数据库的插入Mybatis实现
    请添加图片描述

登录

login.html通过form表单发起post请求,Controller进行参数合法性校验,然后将name,password通过Service进行逻辑验证
请添加图片描述

功能实现

项目搭建

搭建Maven项目,导入Spring Web ,Mybatis Framework,MySQL Driver,ThymeleafLombok.这些依赖.

环境配置

环境配置主要是连接数据库,根据业务需要进行环境搭建

  • 数据库连接
  • 创建数据库
  • 创建数据表
spring:
  main:
    banner-mode: off
    log-startup-info: false
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/MyDB?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
    username: DBName
    password: DBPassword
logging:
  level:
    root: warn
    com.example: debug
mybatis:
  mapper-locations: classpath:/mapper/**Mapper.xml

请添加图片描述

create database cash charset utf8mb4;

-- 创建用户表(主键、用户名(唯一)、密码)
create table cash.users (
    user_id int primary key auto_increment,
    username varchar(50) not null unique,
    password char(60) not null
) comment '用户表,表示货管和收银两种角色,不区分';

-- 创建商品表(主键、关系字段、名称、介绍、库存、单位、价格、折扣)
create table cash.products (
    product_id int primary key auto_increment,
    user_id int not null comment '这是用户上架商品的一对多的关系字段',
    name varchar(100) not null comment '名称',
    introduce varchar(200) not null comment '介绍',
    stock int not null comment '库存数量',
    unit varchar(10) not null comment '显示单位',
    price int not null comment '价格,单位是分,也就是 100 表示 1 块钱',
    discount int not null comment '折扣,取值范围应该是 (0, 100]'
) comment '商品表';

-- 创建订单表(主键、关系字段、订单编号(uuid)、下单时间、完成时间、状态)
create table cash.orders (
    order_id int primary key auto_increment,
    user_id int not null comment '这个是用户创建订单的一对多的关系字段',
    uuid char(32) not null unique comment '对外显示的不连续的订单编号,不会重复',
    created_at datetime not null comment '订单的下单时间',
    finished_at datetime null default null comment '订单的完成时间',
    payable int not null comment '本次订单的应付金额,单位是分,提升显示方便性做的冗余字段',
    actual int not null comment '本次订单的实付金额,单位是分,提升显示方便性做的冗余字段',
    status int not null comment '进行中(1) | 已完成(2)'
) comment '订单的总体信息';

-- 创建订单和商品的关系表 —— 订单项表(主键、两个关系字段、为了防止商品下架后信息丢失,将商品信息备份一份)
create table cash.order_items (
    id int primary key auto_increment,
    order_id int not null comment '属于哪个订单',
    product_id int not null comment '订单中的哪个商品',
    -- 商品的冗余备份
    product_name varchar(100) not null,
    product_introduce varchar(200) not null,
    product_number int not null comment '本次订单购买这个商品多少份',
    product_unit varchar(10) not null,
    product_price int not null,
    product_discount int not null
) comment '订单项,记录本次订单的每一份商品信息';

商品管理

  • 商品上架
    通过form表单发起post请求,然后Controller层进行表单读取,并做合法性的参数校验,Service负责将商品信息映射为一个对象,通过Mapper层使用Mybatis将数据插入
  • 商品浏览
    prduct/list.html提供HTML的框架
    product/list.js发起ajax请求
    product/list.json,以json的格式返回
  • 商品更新
    product/update.html通过form表单发起post请求
    Controller进行登录校验
    Service层 并将要修改的商品构造为一个对象,通过Mybatis完成数据的更新

订单管理

  • 创建订单
  1. 通过product/creat.htmlform表单填写1-2,1-3这种信息,通过Controller解析并映射为Map<ID,数量>这种形式

  2. Service层的作用:
    查询库存是否足够
    遍历每个商品,进行减库存操作
    创建订单信息,生成订单
    通过Controller层重定向到商品订单详情页面order/detail

  3. 浏览器收到了HTTP 重定向响应,继续发送新的地址(发起对/order/detail/{uuid}GET请求)

  4. 后端工作:
    Controller:解析uuid、判断用户是否登录
    Service:根据uuid查询订单基本信息(OrderMapper)、根据orderld查询所有相关订单项信息(OrderitemMapper)
    Controller: MVC流程中,将查询到的订单信息作为order 放到model
    将资源resources/templates/order-detail.html作为View
    Spring(配合Thymeleaf)将Model和View结合起来,生成最终的HTML内容,响应给前端

  5. 浏览器收到响应:用户看到了最终的该订单的详情信息

项目测试

在这里插入图片描述
对商品上架,商品浏览,商品下架,页面跳转进行了单元测试

对项目设计了测试用例
测试用例

项目总结

  1. 改进项
  • 为超市老板增加统计功能(商品,销售额等)
  • 进行权限控制,不同的角色功能不同
  • 参数合法性校验,更新商品部需要再全部输入,使用扫描枪完成对商品条码的扫描输入
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值