先看看效果图:
1.sql
①t_orderitem一个外键
bname:方便后期book删除
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
CREATE TABLE `t_orderitem` (
`orderItemId` char (32) NOT NULL ,
`quantity` int (11) DEFAULT NULL ,
`subtotal` decimal (8,2) DEFAULT NULL ,
`bid` char (32) DEFAULT NULL ,
`bname` varchar (200) DEFAULT NULL ,
`currPrice` decimal (8,2) DEFAULT NULL ,
`image_b` varchar (100) DEFAULT NULL ,
`oid` char (32) DEFAULT NULL ,
PRIMARY KEY (`orderItemId`),
KEY `FK_t_orderitem_t_order` (`oid`),
CONSTRAINT `FK_t_orderitem_t_order` FOREIGN KEY (`oid`) REFERENCES `t_order` (`oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into `t_orderitem`(`orderItemId`,`quantity`,`subtotal`,`bid`,`bname`,`currPrice`,`image_b`,`oid`) values ( '01D2DF3E5BB34E9F9D2477180C8D94D3' ,1, '74.50' , 'CE01F15D435A4C51B0AD8202A318DCA7' , 'Java编程思想(第4版)' , '74.50' , 'book_img/9317290-1_b.jpg' , 'C0841F4DFE7A43BFB183E4E82AE7914C' );
|
②t_order一个外键
1
2
3
4
5
6
7
8
9
10
11
12
13
|
CREATE TABLE `t_order` (
`oid` char (32) NOT NULL ,
`ordertime` char (19) DEFAULT NULL ,
`total` decimal (10,2) DEFAULT NULL ,
`status` int (11) DEFAULT NULL ,
`address` varchar (1000) DEFAULT NULL ,
`uid` char (32) DEFAULT NULL ,
PRIMARY KEY (`oid`),
KEY `FK_t_order_t_user` (`uid`),
CONSTRAINT `FK_t_order_t_user` FOREIGN KEY (`uid`) REFERENCES `t_user` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into `t_order`(`oid`,`ordertime`,`total`,`status`,`address`,`uid`) values ( '058F48DA33694C6D8F5C2C13F3D26CEA' , '2013-12-26 21:47:04' , '95.30' ,1, '李女士 广东省 揭阳市 揭东县 xxx xxx xxx' , '32DB3700D2564254982BC58B0E4D95BC' );
|
2.bean
①OrderItem
1
2
3
4
5
6
|
public class OrderItem {
private String orderItemId; //主键
private int quantity; //数量
private double subtotal; //小计
private Book book; //所关联的Book
private Order order; //所属的订单
|
②Order
1
2
3
4
5
6
7
8
9
10
11
|
public class Order {
private String oid; //主键
private String ordertime; //下单时间
private double total; //总计
private int status;
//订单状态:1未付款, 2已付款但未发货, 3已发货未确认收货, 4确认收货了交易成功, 5已取消(只有未付款才能取消)
private String address; //收货地址
private User owner; //订单的所有者
private List<OrderItem> orderItemList;
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。