一个传统的电商项目,最难的地方也就在于数据库中表的关联,以及多表之间的查询关联,缕清楚表与表之间的关系,才能进行随心所欲的CRUD

  • 第一张表:tb_category 商品类目表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;//硬件设施,母婴哺乳
//排序序号
private Integer sortOrder;
private Boolean deleted;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
@Temporal(TemporalType.TIMESTAMP)
private Date modifyTime;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Category parent;
@JoinColumn(name = "parent_id")
@OneToMany(fetch = FetchType.LAZY)
private List<Category> children;
private String picUrl;
  • 第二张表:tc_product 商品表(spu)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//产品名称:手机,电脑,零食
private String name;
private String icon;
private Boolean deleted;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
@Temporal(TemporalType.TIMESTAMP)
private Date modifyTime;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
private Category category;
private String brandName;
private Double originalPrice;
private Double promotionPrice;
private Long hitCount;
private Long saleCount;
  • 第三张表:tb_propertyItem 商品规格属性表(sku)
1
2
3
4
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
  • 第四张表:tb_product_property 商品与商品属性中间表
1
2
3
4
5
6
7
8
9
10
11
12
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
private PropertyItem propertyItem;

@ManyToOne
private Product product;

@Column(columnDefinition = "tinyint(1) default 0")
private Boolean enable;
  • 贴出商品完整json数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
"code": 200,
"data": {
"id": 1,
"name": "纯牛奶脱脂",
"title": null,
"description": null,
"deleted": false,
"createTime": 1562225261000,
"modifyTime": 1572516206000,
"productCategory": {
"id": 14,
"name": "伊利",
"sortOrder": 0,
"deleted": false,
"createTime": 1572311829000,
"modifyTime": null,
"parent": {
"id": 1,
"name": "牛奶饮品",
"sortOrder": 0,
"deleted": false,
"createTime": 1560327336000,
"modifyTime": null,
"parent": null
}
},
"propertyItems": [
{
"propertyId": 2,
"property": "单位",
"value": "袋"
},
{
"propertyId": 3,
"property": "净含量",
"value": "250ml"
},
{
"propertyId": 4,
"property": "产地",
"value": "中国安徽大草原"
},
{
"propertyId": 5,
"property": "生产日期",
"value": "2019-11-01"
},
{
"propertyId": 6,
"property": "保质期",
"value": "低于10°3个月"
},
{
"propertyId": 7,
"property": "说明",
"value": "开袋即食,不可直接使用微波炉加热"
},
{
"propertyId": 8,
"property": "品牌",
"value": "蒙牛"
},
{
"propertyId": 10,
"property": "贮藏条件",
"value": "低温冷藏"
},
{
"propertyId": 11,
"property": "配料",
"value": "鲜牛奶"
},
{
"propertyId": 12,
"property": "电话",
"value": "021-2313456"
},
{
"propertyId": 13,
"property": "传真",
"value": "021-8673453"
}
]
}
}