日期:2014-05-19  浏览次数:20723 次

问一个数据建模的小问题,很容易的,来捞分。
就是 我有一个商品类 Goods 只有两个属性一个是Id 一个是Name

另外有一个采购单Bill类 类似下面的单子。 包括有goods类 还有一个采购数量income 和采购总金额price。


  商品采购单
 ——————————————————————
 | 商品Id 商品名称 采购数量 总金额 |
 | 1 abc 10 100 |
 | 1 abc 5 50 |
 | 2 bcc 2 25 |  
 ——————————————————————

问题就是,我该怎么样数据库建模?再做一个
GoodsBill类 以及改造下Bill类 类似下面这样吗? 
Java code

public class GoodsBill {
    
    private Goods goods;
    
    private int income;
    
    private float price; 
}



Java code

public class Bill {
    
    private int billId;
    
    private List<GoodsBill>;
     
}



可是这样感觉好像很奇怪,有没有更好的建模方法 提供下给小弟?

------解决方案--------------------
SQL code

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)

------解决方案--------------------
商品类:id<主键>,gcode<商品编号>,name<商品名称>,price<单价>,model<商品型号>...
定单类:id<主键>,bcode<订单编号>,customer<客户名称>,bdate<订单日期>...
订单详单类<订单子类>:id<主键>,bocde<外键>,gcode<外键>,amout<数量>,total<总价>...
订单与详单是一对多的关系。
简单写一下,LZ可以自由发挥