码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis 映射准备工作

时间:2015-08-05 22:30:39      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:mybatis

为了方便理解,我们使用四张表的关系来解释一对一映射,一对多的映射,以及多对多的映射关系

我们采用

1)用户表user

create table user(
id int primary key auto_increment,
username varchar(30),
birthday date,
sex char(1),
address varchar(30)
);

insert into user values(null,‘李卫康‘,‘1993-04-28‘,‘男‘,‘河北邢台‘);

2)订单表orders

create table orders(
id int primary key auto_increment,
number varchar(32),
createtime datetime,
note varchar(32),
user_id int,
constraint user_id_fk foreign key(user_id) references user(id)

);
insert into orders values(null,‘001‘,‘2015-08-04‘,‘hehe‘,2);

3)订单明细表orderdetail

create table orderdetail(
id int primary key auto_increment,
items_num int,
orders_id int,
items_id int,
constraint orders_id_fk foreign key(orders_id) references orders(id),
constraint items_id_fk foreign key(items_id) references items(id)
)
insert into orderdetail values(null,‘01‘,1,1);

4)商品表items

reate table items(
id int primary key auto_increment,
name varchar(32),
price float(10,1),
detail text,
pic varchar(32),
createtime datetime
)
insert into items values(null,‘husshuo‘,6000,‘huashuo‘,‘jianruopanshi‘,‘2015-08-04‘);

对这四张表进行分析:

技术分享

根据表的关系建立javaBean:下面的表都省略了getter setter方法

1)User表:

public class User {
	private int id;
	private String username;
	private Date birthday;
	private String sex;
	private List<Orders> ordersList;//用户和订单是一对多的关系
	private String address;
}
2)Orders表

public class Orders {
	private int id;
	private String number;
	private Date createtime;
	private String note;
	private int userId;
	private List<Orderdetail> orderdetails;//订单表和订单明细是一对多的关系
}
3)OrderDetail

public class Orderdetail {
	private int id;
	private int itemsNum;
	private int ordersId;
	private int itemsId;
	private Items items;//一个订单明细对应一个商品
	
}
4)Items

public class Items {
	private int id;
	private String name;
	private float price;
	private String detail;
	private String text;
	
}





版权声明:本文为博主原创文章,未经博主允许不得转载。

mybatis 映射准备工作

标签:mybatis

原文地址:http://blog.csdn.net/u014010769/article/details/47302297

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!