[TOC]
## 步驟 1 : 用戶表t_user
登錄頁面采集用戶的賬號和密碼


## 步驟 2 : 分類表t_category


## 步驟 3 : 屬性表t_property
在產品頁的商品詳情標簽下,顯示本產品對應分類所設置的所有屬性。


> 比如衣服分類下的所有產品,都有共同的一系列屬性,像:產地,質地,尺寸等等。 那么“有哪些屬性” 這個信息,就維護在屬性表里,而且是和分類關聯起來的。
另一種分類,比如馬桶,那么它就是另外一系列屬性了,像: 是否自動沖水,是否播放音樂,深度,寬度 等信息。
* 問題:為什么屬性表要指向分類表而不是產品表呢,是一類商品屬性都相同么?
> 是的,一類商品屬性都一樣。
> 如果要單獨為每種商品設計屬性,也不是不可以,但是維護起來太辛苦了。 比如演示網站上就有1500種商品,那么每種商品假設有5種屬性好了,那就是7500種屬性,光是做這個演示網站的準備數據,就太復雜了。
## 步驟 4 : 產品表t_product
產品頁的產品信息里顯示本產品的名稱,小標題,原始價格,促銷價,銷量,庫存等信息


> name: 產品名稱
subTitle: 小標題
originalPrice: 原始價格
promotePrice: 優惠價格
stock: 庫存
createDate: 創建日期
## 步驟 5 : 屬性值表t_property_value
在產品頁的商品詳情標簽下,顯示本產品的所有屬性值


* * * * *
* 問題: 為什么有了屬性表還需要一個屬性值表呢?
> 因為不同商品的相同屬性,他們的屬性值不一樣呢
比如iphone 有顏色,值是白色
熊貓手機也有顏色,值卻是黑白相間
## 步驟 6 : 產品圖片表t_product_image
在產品頁顯示5個單個圖片


> type表示類型,產品圖片分單個圖片和詳情圖片兩種
* * * * *
* 問題:商品圖片表中并沒有圖片地址這一字段,我不清楚怎么獲取指定的商品圖片
> 基于 productImage 表的id值來保存的,保存在固定位置(后面章節會談到)。
## 步驟 7 : 評價表t_review
產品頁顯示評價信息


## 步驟 8 : 訂單表t_order
在后臺的訂單管理頁面看到的訂單信息

生成訂單前,結算頁面


> orderCode: 訂單號
address:收貨地址
post: 郵編
receiver: 收貨人信息
mobile: 手機號碼
userMessage: 用戶備注信息
createDate: 訂單創建日期
payDate: 支付日期
deliveryDate: 發貨日期
confirmDate:確認收貨日期
status: 訂單狀態
## 步驟 9 : 訂單項表t_order_item
在購物車中看到的訂單項信息


> number字段表示購買數量
* * * * *
* 問題:訂單項表的user_id有點冗余,畢竟通過訂單項中的訂單id可以確認用戶,這里是怎么考慮的呢?
> 在創建了購物車之后,創建訂單之前,這些訂單項是沒有和訂單關聯起來的。
如果不加個uid, 那么這些訂單項屬于哪個用戶的信息就丟失了。
## 步驟 10:導出SQL語句
1. 把name復制到comment中,運行腳本,選擇Tools菜單--Execute Commands,點擊打開,

選擇name2comment.vbs
2. 選擇Database菜單—Generate Database,生成數據結構的SQL,注意在format標簽中將字符編碼設置成UTF-8,導出SQL文件。
## 步驟 11:創建數據庫,導入SQL
1. 在navicat中創建數據庫:tmall_ssm,并且將數據庫的編碼設置為utf8,便于存放中文
2. 運行剛剛導出的SQL腳本
tmall_ssm.sql
~~~
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2018/8/25 14:56:03 */
/*==============================================================*/
drop table if exists t_category;
drop table if exists t_order;
drop table if exists t_order_item;
drop table if exists t_product;
drop table if exists t_product_image;
drop table if exists t_property;
drop table if exists t_property_value;
drop table if exists t_review;
drop table if exists t_user;
/*==============================================================*/
/* Table: t_category */
/*==============================================================*/
create table t_category
(
id int not null auto_increment comment 'ID',
name varchar(255) comment '名稱',
primary key (id)
);
alter table t_category comment '分類表';
/*==============================================================*/
/* Table: t_order */
/*==============================================================*/
create table t_order
(
id int not null auto_increment comment 'ID',
order_code varchar(255) comment '訂單編號',
address varchar(255) comment '地址',
post varchar(255) comment '郵編',
receiver varchar(255) comment '收件人',
mobile varchar(255) comment '手機號',
user_message varchar(255) comment '買家留言',
create_date datetime comment '創建時間',
pay_date datetime comment '支付時間',
delivery_date datetime comment '發貨時間',
confirm_date datetime comment '確認收貨時間',
status varchar(255) comment '狀態',
user_id int comment '所屬用戶',
primary key (id)
);
alter table t_order comment '訂單表';
/*==============================================================*/
/* Table: t_order_item */
/*==============================================================*/
create table t_order_item
(
id int not null auto_increment comment 'ID',
number int comment '數量',
user_id int comment '所屬用戶',
product_id int comment '所屬產品',
order_id int comment '所屬訂單',
primary key (id)
);
alter table t_order_item comment '訂單項';
/*==============================================================*/
/* Table: t_product */
/*==============================================================*/
create table t_product
(
id int not null auto_increment comment 'ID',
name varchar(255) comment '名稱',
sub_title varchar(255) comment '子標題',
original_price float comment '原價格',
promote_price float comment '促銷價',
stock int comment '倉庫',
create_date datetime comment '創建時間',
category_id int comment '所屬分類',
primary key (id)
);
alter table t_product comment '產品表';
/*==============================================================*/
/* Table: t_product_image */
/*==============================================================*/
create table t_product_image
(
id int not null auto_increment comment 'ID',
type varchar(255) comment '類型',
product_id int comment '所屬產品',
primary key (id)
);
alter table t_product_image comment '產品圖片表';
/*==============================================================*/
/* Table: t_property */
/*==============================================================*/
create table t_property
(
id int not null auto_increment comment 'ID',
name varchar(255) comment '名稱',
category_id int comment '所屬分類',
primary key (id)
);
alter table t_property comment '屬性表';
/*==============================================================*/
/* Table: t_property_value */
/*==============================================================*/
create table t_property_value
(
id int not null auto_increment comment 'ID',
value varchar(255) comment '屬性值',
product_id int comment '所屬產品',
property_id int comment '所屬屬性',
primary key (id)
);
alter table t_property_value comment '屬性值表';
/*==============================================================*/
/* Table: t_review */
/*==============================================================*/
create table t_review
(
id int not null auto_increment comment 'ID',
content varchar(4000) comment '內容',
create_date datetime comment '創建時間',
product_id int comment '所屬產品',
user_id int comment '所屬用戶',
primary key (id)
);
alter table t_review comment '評價表';
/*==============================================================*/
/* Table: t_user */
/*==============================================================*/
create table t_user
(
ID int not null auto_increment comment 'ID',
name varchar(255) comment '名稱',
password varchar(255) comment '密碼',
primary key (ID)
);
alter table t_user comment '用戶表';
~~~