
网上看了些案例感觉都太全了,新手表示看了反而更头晕了, 就直接厚脸皮来做做伸手党...
假如我的商品和购物车结构如下:
// 商品 { "id": "1111111" "title": "这是商品", "price": 100, "desc": "xxxxxxx", "store": [ {"babel": "S", "store": 50}, {"babel": "M","store": 50}, {"babel": "L", "store": 50} ] } // 购物车 { "id": "userid", "items": [ { "title": "这是商品", "store": [ {"babel": "S", "store": 1}, {"babel": "M", "store": 2} ], "total_price": 300 ] } 这里的商品里的每一个 store, 购物车里的 items 中的每一个 item, 甚至 item 里的每一个 store, 这些是单独写一个 clsss 还是直接写在商品和购物车类的内部? 尤其是这个 store 两边还通用的情况,,
最后问一下, 假如直接写个 Lsit<map> 会不会被骂.?</map>
public class Cart { private String title; private List<Item> items; } class Item { private String title; private List<Store> store; private int total_pric; } class Store { private String label; private int store; } 1 encro 2019 年 6 月 19 日 看下数据库,数据结构的书籍吧。 Cart{id,product_id,user_id,num},Product{id,title},Order{id,price},OrderItem{id,product_id,num} |
2 PerpetualHeng 2019 年 6 月 19 日 |
3 GoLand 2019 年 6 月 19 日 同一个商品不同规格属两个 sku,你基本概念都没弄清楚。 |
4 aoscici2000 OP @GoLand 不同规格不同 sku 这个倒是知道的, 其实我最想知道的是假如像例子中的这种有 store 这个两边通用的结构的时候, 是各自写在各自内部, 还是独立出来? |
5 MotherShip 2019 年 6 月 24 日 @aoscici2000 独立出来吧,不过我觉得这个结构有点不合理,如果是我我可能会设计成这样: // 商品 { "id": "1111111" "title": "这是商品", "price": 100, "desc": "xxxxxxx", } //SKU [ { "productId": 1111111, "babel": "S", "store": 50 }, ... ] // 购物车 { "id": "userid", "items": [ { "title": "这是商品", "store": [ {"babel": "S", "store": 1}, {"babel": "M", "store": 2} ], "total_price": 300 ] } |
6 MotherShip 2019 年 6 月 24 日 上面 SKU 和购物车没改完就发出去了 //SKU [ { "id": 123 "productId": 1111111, "babel": "S", "store": 50 }, ... ] // 购物车 { "id": "userid", "skuId": 123 } 查购物车的时候去 SKU 表关联查询 babel,然后去商品表关联查商品名字 或者可以适当冗余字段,比如在 SKU 里添加商品名字等 |