# sports_shop_backend **Repository Path**: kang-zhenbin/sports_shop_backend ## Basic Information - **Project Name**: sports_shop_backend - **Description**: XMUT期末设计-运动商城系统后台 由经典的JavaWeb 改成前后端分离 使用技术:servlet、JavaBean、jdbc、JWT - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-30 - **Last Updated**: 2025-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: javaWEB, Servlet, JDBC ## README # 一、运行方式 环境要求: `Maven`、`Mysql`、`jdk1.8`及以上、`tomcat9`及以上 如果没有安装这些,可以阅读我的这几篇文章进行安装 - [JAVA学习 jdk下载安装 Oracle跳过登录验证 配置jdk环境 第一行代码 Hello world - 掘金 (juejin.cn)](https://juejin.cn/post/7141224194057961480) - [JavaWeb IDEA配置tomcat 边踩坑边解决 - 掘金 (juejin.cn)](https://juejin.cn/post/7148363883965579295) - [Maven安装 环境搭建 以及一些内容学习 - 掘金 (juejin.cn)](https://juejin.cn/post/7154176799453380639) - [MySQL5.7经典版 zip包免安装配置 完美复现踩坑场景,手把手教学解决 - 掘金 (juejin.cn)](https://juejin.cn/post/7148054742898311198) ## 1、下载源码,解压后用IDEA打开 找到utils目录下的.sql文件,附加到你的数据库中 ![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/28a42919c6e04f6c98e0e9ce37d2c112~tplv-k3u1fbpfcp-watermark.image?) 作者我的数据库版本是(5.7),有需要自己修改以下两个 - 数据库连接配置 - maven依赖 ![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/652790d4ef7d4675af4d8275e0dde7aa~tplv-k3u1fbpfcp-watermark.image?) ![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/5910f9b1674544b1893452ae2102c1a3~tplv-k3u1fbpfcp-watermark.image?) ## 2、 刷新maven,自动安装相关dependency ![image.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9e11f4752e8245afbe50a3055d7bae70~tplv-k3u1fbpfcp-watermark.image?) ## 3、使用tomcat运行 ![image.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6aa55268b48c4de4889aaa2b2c6a3436~tplv-k3u1fbpfcp-watermark.image?) 运行效果 ![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4738df19c94a4ce68f78338035ce930b~tplv-k3u1fbpfcp-watermark.image?) # 二、主要内容 ## 使用技术 > 后端:Servlet、JavaBean、JDBC、JWT > 前端:vue.js、axios、element-ui、echarts、 前端项目地址:[sports_shop_front](https://gitee.com/kang-zhenbin/sports_shop_front) ## API 接口说明 - 接口基准地址:`http://localhost:8888/sports_shop_backend_war/` - 用户头像保存地址:`http://localhost:8888/sports_shop_backend_war/users_picture/` - 商品图片保存地址:`http://localhost:8888/sports_shop_backend_war/goods_picture/` - 服务端已开启 CORS 跨域支持 - API接口 认证统一使用 Token 认证 - 需要授权的 API ,必须在请求头中使用 `Authorization` 字段提供 `token` 令牌 - 使用 HTTP Status Code 标识状态 - 数据返回格式统一使用 JSON ## 响应状态码说明 | *状态码* | *含义* | *说明* | | -------- | --------------------- | --------------------------------------------------- | | **200** | OK | 请求成功 | | **201** | CREATED \ INTSERT | 创建成功 \ 新增添加成功 | | 204 | DELETED | 删除成功 | | 400 | BAD REQUEST | 请求的地址不存在或者包含不支持的参数 | | 401 | UNAUTHORIZED | 未授权 | | 403 | FORBIDDEN | 被禁止访问 | | **404** | NOT FOUND | 请求的资源不存在 | | 422 | Unprocesable entity | [POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误 | | 500 | INTERNAL SERVER ERROR | 内部错误 | | | | | ------ # 二、系统分析与接口设计 > 关于数据表与前端界面的详细信息,请移步看我的前端项目文档 [sports_shop_front](https://gitee.com/kang-zhenbin/sports_shop_front) **数据库中共有五张表:** - A、用户表 - B、商品表 - C、购物车表 - D、订单表 - E、评论表 **前端共有七个界面:** - 1、登录界面 - 2、注册界面 - 3、商品列表界面 - 4、商品详情界面 - 5、购物车界面 - 6、订单界面 - 7、个人中心界面 **功能需求汇总** *统计系统所需操作,思考后端接口编写* - 1、登录验证 - 2、注册用户(要能上传头像) - 3、获取商品数据 - 4、查看指定商品的详细信息,(重点带上该商品的评论数据) - 5、添加商品到购物车 (为了简便,购物车可以一条条加,但结算应当一件全部结算) - 6、结算购物车数据成订单,(还要扣除用户余额) - 7、获取用户对应的订单数据 - 8、添加商品评论信息 - 9、获取个人信息 - 10、user_id获取购物车数据 - 11、购物车单独结算 - 12、修改评论数据(订单表和评论表) - 13、删除单条评论数据 - 14、删除单条购物车记录 待后续添加的功能: - ~~管理员 上架商品~~ - ~~管理员 下架商品~~ - ~~管理员为用户添加钱包金额~~ # 详细API接口设计 ## POST 1、登录验证 - 请求路径:/login - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |username|query|string| 否 |none| |password|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "grade": "vip", "level": 1, "password": "123456", "state_message": "这个人很懒,什么都没有留下", "token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxIiwic3ViIjoiYWRtaW4iLCJpc3MiOiJpY2VmaXNoIiwiaWF0IjoxNjcwMjA3MjMyLCJleHAiOjE2NzAyOTM2MzIsImFjcm9zcyI6InRydWUiLCJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFkbWluIn0.4WpF1CGGmuekH1c1q1h8bWGEo0FCizAOeiXfx1bfqH0", "type": "root", "user_id": 1, "user_picture": "http://127.0.0.1:8888/users_picture/xxx.jpg", "username": "admin", "wallet": 9999 }, "meta": { "msg": "登录成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 2、注册用户 - 请求路径:/CreateUser - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |username|query|string| 否 |none| |password|query|string| 否 |none| |user_picture|query|string| 否 |none| |type|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "grade": "vip", "level": 1, "password": "123456", "state_message": "这个人很懒,什么都没有留下", "type": "root", "user_id": 16, "user_picture": "http://192.168.123.53:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "username": "kzb", "wallet": 1000 }, "meta": { "msg": "添加用户成功", "status": 201 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 9、获取个人信息 - 请求路径:/getUserInfo - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |user_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "grade": "vip", "level": 1, "password": "123456", "state_message": "这个人很懒,什么都没有留下", "type": "root", "user_id": 4, "user_picture": "http://192.168.123.53:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "username": "冰镇生鲜", "wallet": -10189 }, "meta": { "msg": "获取用户信息成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 8、添加商品评论信息 - 请求路径:/addComment - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |says_time|query|string| 否 |none| |says|query|string| 否 |none| |goods_id|query|string| 否 |none| |user_id|query|string| 否 |none| |username|query|string| 否 |none| |order_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": "薇我50,肯德基疯狂星期四", "meta": { "msg": "添加评论成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 3、获取商品数据 - 请求路径:/getAllGoods - 请求方法:post - 请求参数如下表: > 返回示例 > 成功 ```json { "data": [ { "goods_describe": "为发烧而生", "goods_id": 1, "goods_name": "红米note", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 799 }, { "goods_describe": "为发烧而生", "goods_id": 2, "goods_name": "小米12S Pro", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 4399 }, { "goods_describe": "为发烧而生", "goods_id": 3, "goods_name": "小米12S", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 3699 }, { "goods_describe": "为发烧而生", "goods_id": 4, "goods_name": "小米12X", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 2699 }, { "goods_describe": "为发烧而生", "goods_id": 5, "goods_name": "小米11 青春版", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 1799 }, { "goods_describe": "为发烧而生", "goods_id": 6, "goods_name": "小米Civi2", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 2399 } ], "meta": { "msg": "获取商品信息成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 4、查看指定商品的详细信息 - 请求路径:/getGoodAndComment - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |goods_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "comment": [ { "order_id": 3, "says": "薇我50,肯德基疯狂星期四", "says_id": 1, "says_time": 1670083200000, "user_id": 2, "username": "冰镇生鲜" }, { "order_id": 3, "says": "薇我30,肯德基疯狂星期四", "says_id": 2, "says_time": 1670083200000, "user_id": 2, "username": "冰镇生鲜" }, { "order_id": 3, "says": "薇我20,肯德基疯狂星期四", "says_id": 3, "says_time": 1670169600000, "user_id": 2, "username": "冰镇生鲜" }, { "order_id": 3, "says": "薇我10,肯德基疯狂星期四", "says_id": 4, "says_time": 1670688000000, "user_id": 2, "username": "冰镇生鲜" }, { "order_id": 62, "says": "今天天气真不错", "says_id": 8, "says_time": 1670947200000, "user_id": 4, "username": "冰镇生鲜" }, { "order_id": 63, "says": "吃了没", "says_id": 9, "says_time": 1670947200000, "user_id": 4, "username": "冰镇生鲜" } ], "goods_describe": "为发烧而生", "goods_id": 1, "goods_name": "红米note", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 799 }, "meta": { "msg": "获取商品信息成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 5、添加商品到购物车 - 请求路径:/addShopCartToOrders - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |shopping_count|query|string| 否 |none| |shopping_amount|query|string| 否 |none| |goods_id|query|string| 否 |none| |goods_name|query|string| 否 |none| |goods_price|query|string| 否 |none| |goods_picture|query|string| 否 |none| |goods_describe|query|string| 否 |none| |user_id|query|string| 否 |none| |username|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "goods_id": 1, "shopping_cart_id": 64, "user_id": 4 }, "meta": { "msg": "添加购物车成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 6、结算购物车数据成订单 - 请求路径:/settlement - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |order_time|query|string| 否 |none| |order_count|query|string| 否 |none| |order_amount|query|string| 否 |none| |user_id|query|string| 否 |none| |username|query|string| 否 |none| |goods_id|query|string| 否 |none| |goods_name|query|string| 否 |none| |goods_price|query|string| 否 |none| |goods_picture|query|string| 否 |none| |goods_describe|query|string| 否 |none| |total_pay|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": { "thanks": "没有别的意思,谢谢老板" }, "meta": { "msg": "结算商品成功", "status": 201 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 7、获取用户对应的订单数据 - 请求路径:/getOrdersByUserID - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |user_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": [ { "goods_describe": "为发烧而生", "goods_id": 4, "goods_name": "小米12X", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 2699, "order_amount": 2699, "order_count": 1, "order_id": 60, "order_time": 1670947200000, "says": "买家未做出评价", "user_id": 1, "username": "admin" }, { "goods_describe": "为发烧而生", "goods_id": 5, "goods_name": "小米11 青春版", "goods_picture": "http://localhost:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 1799, "order_amount": 1799, "order_count": 1, "order_id": 61, "order_time": 1670947200000, "says": "买家未做出评价", "user_id": 1, "username": "admin" } ], "meta": { "msg": "获取商品信息成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 10、user_id获取购物车数据 - 请求路径:/getShopCartById - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |user_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "data": [ { "goods_describe": "为发烧而生", "goods_id": 1, "goods_name": "红米note", "goods_picture": "http://192.168.123.53:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 1999, "shopping_amount": 799, "shopping_cart_id": 4, "shopping_count": 1, "user_id": 4, "username": "冰镇生鲜" }, { "goods_describe": "为发烧而生", "goods_id": 1, "goods_name": "红米note", "goods_picture": "http://192.168.123.53:8888/sports_shop_backend_war/users_picture/kzb68up.jpg", "goods_price": 1999, "shopping_amount": 1999, "shopping_cart_id": 64, "shopping_count": 1, "user_id": 4, "username": "冰镇生鲜" } ], "meta": { "msg": "获取用户相关购物车成功", "status": 200 } } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 11、购物车单独结算 - 请求路径:/simpleBuy - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |shopping_count|query|string| 否 |none| |shopping_amount|query|string| 否 |none| |goods_id|query|string| 否 |none| |goods_name|query|string| 否 |none| |goods_price|query|string| 否 |none| |goods_picture|query|string| 否 |none| |goods_describe|query|string| 否 |none| |user_id|query|string| 否 |none| |username|query|string| 否 |none| |shopping_cart_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "msg": "购买成功。1、添加订单记录2、删除购物车记录3、扣除用户金额", "status": 200 } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 12、修改评论数据,订单表和评论表 - 请求路径:/updateOrderSays - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |order_id|query|string| 否 |none| |says|query|string| 否 |none| |goods_id|query|string| 否 |none| |user_id|query|string| 否 |none| |username|query|string| 否 |none| > 返回示例 > 成功 ```json { "msg": "修改order表says成功,修改comment表says成功", "status": 200 } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 13、删除单条订单记录 - 请求路径:/deleteOrdersById - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |order_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "msg": "(60)删除订单记录成功", "status": 200 } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline| ### 返回数据结构 ## POST 14、删除单条 购物车 记录 - 请求路径:/deleteShoppingCartById - 请求方法:post - 请求参数如下表: ### 请求参数 |名称|位置|类型|必选|说明| |---|---|---|---|---| |shopping_cart_id|query|string| 否 |none| > 返回示例 > 成功 ```json { "msg": "(60)删除订单记录成功", "status": 200 } ``` ### 返回结果 |状态码|状态码含义|说明|数据模型| |---|---|---|---| |200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|成功|Inline|