Skip to content

Commit 26d316f

Browse files
committed
Cursor 辅助修改后的代码
0 parents  commit 26d316f

48 files changed

Lines changed: 2879 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
.kotlin
6+
7+
### IntelliJ IDEA ###
8+
.idea/modules.xml
9+
.idea/jarRepositories.xml
10+
.idea/compiler.xml
11+
.idea/libraries/
12+
*.iws
13+
*.iml
14+
*.ipr
15+
16+
### Eclipse ###
17+
.apt_generated
18+
.classpath
19+
.factorypath
20+
.project
21+
.settings
22+
.springBeans
23+
.sts4-cache
24+
25+
### NetBeans ###
26+
/nbproject/private/
27+
/nbbuild/
28+
/dist/
29+
/nbdist/
30+
/.nb-gradle/
31+
build/
32+
!**/src/main/**/build/
33+
!**/src/test/**/build/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
### Mac OS ###
39+
.DS_Store

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# DrawBlueCup 接口文档
2+
3+
> 通过 `http://localhost:8080/swagger-ui/index.html` 可以查看实时在线文档(SpringDoc 自动生成)。
4+
5+
## 统一响应
6+
7+
```json
8+
{
9+
"code": 200,
10+
"msg": "操作成功",
11+
"data": {}
12+
}
13+
```
14+
15+
## 用户模块
16+
17+
| 接口 | 方法 | 描述 | 备注 |
18+
| --- | --- | --- | --- |
19+
| `/api/user/findAll` | GET | 查询所有用户 | 支持分页由前端控制 |
20+
| `/api/user/findById/{id}` | GET | 根据 ID 查询用户 | path 变量 |
21+
| `/api/user/findByPhone/{phone}` | GET | 根据手机号查询 | 自定义 @Phone 校验 |
22+
| `/api/user/query` | GET | 组合条件查询 | name/phone/createTime/updateTime + pageNum/pageSize |
23+
| `/api/user/add` | POST | 新增用户 | `@Valid User` 请求体 |
24+
| `/api/user/update` | PUT | 修改用户 | |
25+
| `/api/user/delete/{id}` | DELETE | 删除单个用户 | |
26+
| `/api/user/deleteUserAll` | DELETE | 清空用户表 | 慎用 |
27+
28+
## 商品模块
29+
30+
| 接口 | 方法 | 描述 |
31+
| --- | --- | --- |
32+
| `/api/product/findAll` | GET | 查询所有商品 |
33+
| `/api/product/findById/{id}` | GET | 根据 ID 查询 |
34+
| `/api/product/findByName/{name}` | GET | 模糊查询 |
35+
| `/api/product/add` | POST | 新增商品 |
36+
| `/api/product/update` | PUT | 修改商品 |
37+
| `/api/product/deleteById/{id}` | DELETE | 删除指定商品 |
38+
| `/api/product/deleteAll` | DELETE | 清空商品表 |
39+
40+
## 订单模块
41+
42+
| 接口 | 方法 | 描述 |
43+
| --- | --- | --- |
44+
| `/api/order/findAll` | GET | 查询所有订单 |
45+
| `/api/order/findUserWithOrders/{id}` | GET | 查看用户及其订单 |
46+
| `/api/order/add` | POST | 新增订单 |
47+
| `/api/order/deleteAll` | DELETE | 清空订单 |
48+
49+
## 收藏模块(多对多示例)
50+
51+
| 接口 | 方法 | 描述 |
52+
| --- | --- | --- |
53+
| `/api/favorite` | POST | 新增收藏(userId + productId) |
54+
| `/api/favorite` | DELETE | 取消收藏(userId + productId) |
55+
| `/api/favorite/user/{userId}` | GET | 查询用户收藏的商品 |
56+
57+
## 跨域验证
58+
59+
- 运行 `docs/cors-fetch-demo.html`(例如使用 VS Code Live Server 监听 `http://127.0.0.1:5500`
60+
- 点击按钮后可看到接口返回结果,无浏览器 CORS 报错即为通过。
61+

docs/cors-fetch-demo.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>CORS 联调验证</title>
6+
</head>
7+
<body>
8+
<h1>跨域请求示例</h1>
9+
<button id="fetchBtn">请求用户列表</button>
10+
<pre id="result"></pre>
11+
12+
<script>
13+
document.getElementById('fetchBtn').addEventListener('click', () => {
14+
fetch('http://localhost:8080/api/user/findAll', {
15+
credentials: 'include'
16+
})
17+
.then(res => res.json())
18+
.then(data => {
19+
document.getElementById('result').textContent = JSON.stringify(data, null, 2);
20+
})
21+
.catch(err => {
22+
document.getElementById('result').textContent = err.toString();
23+
});
24+
});
25+
</script>
26+
</body>
27+
</html>
28+

docs/schema.sql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CREATE DATABASE IF NOT EXISTS userdemo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
2+
USE userdemo;
3+
4+
DROP TABLE IF EXISTS favorite;
5+
DROP TABLE IF EXISTS `order`;
6+
DROP TABLE IF EXISTS product;
7+
DROP TABLE IF EXISTS category;
8+
DROP TABLE IF EXISTS user;
9+
10+
CREATE TABLE user (
11+
id INT PRIMARY KEY AUTO_INCREMENT,
12+
name VARCHAR(64) NOT NULL,
13+
phone VARCHAR(20) NOT NULL,
14+
status TINYINT DEFAULT 1,
15+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
16+
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
17+
UNIQUE KEY uk_user_phone (phone),
18+
KEY idx_user_create_time (create_time)
19+
) COMMENT '用户表';
20+
21+
CREATE TABLE category (
22+
id INT PRIMARY KEY AUTO_INCREMENT,
23+
name VARCHAR(64) NOT NULL,
24+
sort INT DEFAULT 0,
25+
parent_id INT DEFAULT NULL,
26+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
27+
UNIQUE KEY uk_category_name (name),
28+
KEY idx_category_parent (parent_id)
29+
) COMMENT '商品分类表';
30+
31+
CREATE TABLE product (
32+
id INT PRIMARY KEY AUTO_INCREMENT,
33+
name VARCHAR(128) NOT NULL,
34+
category_id INT,
35+
status TINYINT DEFAULT 1,
36+
stock INT DEFAULT 0,
37+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
38+
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
39+
UNIQUE KEY uk_product_name (name),
40+
KEY idx_product_category (category_id),
41+
CONSTRAINT fk_product_category FOREIGN KEY (category_id) REFERENCES category (id)
42+
) COMMENT '商品表';
43+
44+
CREATE TABLE `order` (
45+
id INT PRIMARY KEY AUTO_INCREMENT,
46+
order_no VARCHAR(64) NOT NULL,
47+
user_id INT NOT NULL,
48+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
49+
UNIQUE KEY uk_order_no (order_no),
50+
KEY idx_order_user (user_id),
51+
CONSTRAINT fk_order_user FOREIGN KEY (user_id) REFERENCES user (id)
52+
) COMMENT '订单主表';
53+
54+
CREATE TABLE favorite (
55+
id INT PRIMARY KEY AUTO_INCREMENT,
56+
user_id INT NOT NULL,
57+
product_id INT NOT NULL,
58+
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
59+
UNIQUE KEY uk_user_product (user_id, product_id),
60+
KEY idx_favorite_user (user_id),
61+
KEY idx_favorite_product (product_id),
62+
CONSTRAINT fk_favorite_user FOREIGN KEY (user_id) REFERENCES user (id),
63+
CONSTRAINT fk_favorite_product FOREIGN KEY (product_id) REFERENCES product (id)
64+
) COMMENT '用户收藏表(多对多)';
65+

drawbluecup-common/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.drawbluecup</groupId>
8+
<artifactId>drawbluecup-parent</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>drawbluecup-common</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
15+
<dependencies>
16+
<!-- Spring 核心 -->
17+
<dependency>
18+
<groupId>org.springframework</groupId>
19+
<artifactId>spring-context</artifactId>
20+
</dependency>
21+
<!-- Spring Web(用于 HTTP 状态码、Controller 等) -->
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
<!-- Bean Validation API,供自定义注解使用 -->
27+
<dependency>
28+
<groupId>jakarta.validation</groupId>
29+
<artifactId>jakarta.validation-api</artifactId>
30+
</dependency>
31+
</dependencies>
32+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.drawbluecup.entity;
2+
3+
import java.time.LocalDateTime;
4+
5+
/**
6+
* 用户收藏商品的多对多关系实体
7+
*/
8+
public class Favorite {
9+
private Integer id;
10+
private Integer userId;
11+
private Integer productId;
12+
private LocalDateTime createTime;
13+
/**
14+
* 关联的商品详情,便于通过 JOIN 一次性取回
15+
*/
16+
private Product product;
17+
18+
public Integer getId() {
19+
return id;
20+
}
21+
22+
public void setId(Integer id) {
23+
this.id = id;
24+
}
25+
26+
public Integer getUserId() {
27+
return userId;
28+
}
29+
30+
public void setUserId(Integer userId) {
31+
this.userId = userId;
32+
}
33+
34+
public Integer getProductId() {
35+
return productId;
36+
}
37+
38+
public void setProductId(Integer productId) {
39+
this.productId = productId;
40+
}
41+
42+
public LocalDateTime getCreateTime() {
43+
return createTime;
44+
}
45+
46+
public void setCreateTime(LocalDateTime createTime) {
47+
this.createTime = createTime;
48+
}
49+
50+
public Product getProduct() {
51+
return product;
52+
}
53+
54+
public void setProduct(Product product) {
55+
this.product = product;
56+
}
57+
}
58+

0 commit comments

Comments
 (0)