1、效果图示
2、相关代码注:这里只是简单演示,很多代码并不是那么完善,且 没有写支付功能,只是简单演示整个流程而已
2.1、数据库相关表
1 CREATE TABLE orders( -- 订单表 2 id VARCHAR(100) PRIMARY KEY, 3 orderId VARCHAR(100) NOT NULL UNIQUE, 4 num INT, 5 price FLOAT(8,2), 6 state INT, 7 user_id VARCHAR(100), 8 CONSTRAINT user_id_fk FOREIGN KEY(user_id) REFERENCES Users(id) 9 ); 10 11 CREATE TABLE ordersitem( -- 订单项表 12 id VARCHAR(100) PRIMARY KEY, 13 num INT, 14 price FLOAT(8,2), 15 orders_id VARCHAR(100), 16 book_id VARCHAR(100), 17 CONSTRAINT orders_id_fk FOREIGN KEY(orders_id) REFERENCES orders(id), 18 CONSTRAINT book_id_fk FOREIGN KEY(book_id) REFERENCES book(id) 19 );