Java-028-数据模型

购物车数据模型

RESTful API

  • 用户 User: Create, List, Get, Update
  • 购物车 Cart: Create, List, Get, Update
  • 产品 Product: Create, List, Get, Update
  • 订单 Order: Create, List, Get, Update

数据模型

用户

数据对象:

User {
id: Integer primary key,
name: String not null,
password: String not null,
}
关系数据库表 Schema:

CREATE TABLE user (
id INTEGER PRIMARY KEY NOT NULL,
name VARCHAR(20) NOT NULL,
password VARCHAR(255) NOT NULL,
);
购物车中收藏的产品记录
数据对象:

CartItem {
id: Integer primary key,
user_id: Integer not null,
product_id: Integer not null,
quantity: Integer not null,
}
关系数据库 Schema:

CREATE TABLE cart_item (
id INTEGER PRIMARY KEY NOT NULL,
user_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL
);
产品
数据对象:

Product {
id: Integer primary key,
name: String not null,
description: String not null,
price: Integer not null
}
关系数据库 Schema:

CREATE TABLE product (
id INTEGER PRIMARY KEY NOT NULL,
name VARCHAR(25) NOT NULL,
price INTEGER NOT NULL,
description VARCHAR(255) NOT NULL
);
订单
数据对象:

Order {
id: Integer primary key,
user_id: Integer not null,
product_id: Integer not null,
quantity: Integer not null,
status: String not null,
address: String not null
}
关系数据库 Schema:

CREATE TABLE order (
id INTEGER PRIMARY KEY NOT NULL,
user_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
status VARCHAR(25) NOT NULL,
address VARCHAR(255) NOT NULL
);