就是 我有一个商品类 Goods 只有两个属性一个是Id 一个是Name另外有一个采购单Bill类 类似下面的单子。 包括有goods类 还有一个采购数量income 和采购总金额price。
商品采购单
——————————————————————
| 商品Id 商品名称 采购数量 总金额 |
| 1 abc 10 100 |
| 1 abc 5 50 |
| 2 bcc 2 25 |
——————————————————————问题就是,我该怎么样数据库建模?再做一个
GoodsBill类 以及改造下Bill类 类似下面这样吗? public class GoodsBill {
private Goods goods;
private int income;
private float price;
}public class Bill {
private int billId;
private List<GoodsBill>;
}
可是这样感觉好像很奇怪,有没有更好的建模方法 提供下给小弟?
商品采购单
——————————————————————
| 商品Id 商品名称 采购数量 总金额 |
| 1 abc 10 100 |
| 1 abc 5 50 |
| 2 bcc 2 25 |
——————————————————————问题就是,我该怎么样数据库建模?再做一个
GoodsBill类 以及改造下Bill类 类似下面这样吗? public class GoodsBill {
private Goods goods;
private int income;
private float price;
}public class Bill {
private int billId;
private List<GoodsBill>;
}
可是这样感觉好像很奇怪,有没有更好的建模方法 提供下给小弟?
create table t_bill (
id bigint not null auto_increment,
income integer,
price integer,
good_id bigint,
primary key (id)
)
create table t_good (
id bigint not null auto_increment,
name varchar(255),
primary key (id)
)
alter table t_bill
add index FKCB5B04F2C812F5E7 (good_id),
add constraint FKCB5B04F2C812F5E7
foreign key (good_id)
references t_good (id)你的数据库表大概是这个意思吧,如果我理解对了,bill类里设个多对一关联就行了。@Entity
@Table(name = "t_bill")
public class Bill { private Long id;
private Good good;
private Integer income;
private Integer price; public Bill() { } public void setId(Long id) {
this.id = id;
} @Id
@GeneratedValue
public Long getId() {
return id;
} public void setGood(Good good) {
this.good = good;
} @ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "good_id")
public Good getGood() {
return good;
} public void setIncome(Integer income) {
this.income = income;
} public Integer getIncome() {
return income;
} public void setPrice(Integer price) {
this.price = price;
} public Integer getPrice() {
return price;
}}
定单类:id<主键>,bcode<订单编号>,customer<客户名称>,bdate<订单日期>...
订单详单类<订单子类>:id<主键>,bocde<外键>,gcode<外键>,amout<数量>,total<总价>...
订单与详单是一对多的关系。
简单写一下,LZ可以自由发挥