分析购物车结构
这里主要以京东的购物车页面为列
从图中可以分析出我们可以建两个实体类:Cart.java和CartItem.java
其中Cart.java中应该至少包含cartItems(购物项)和totalPrice(总计)
CartItem.java实体类中至少包含Product实体类、buyNum、subtotalPrice、cartState等属性
购物车、购物项、商品实体类之间的设计及关系
首先存在一个Product实体类(其中LssgProductClass 为这个实体的商品类别)
package com.lianwei.lssg.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
public class LssgProduct implements Serializable {
private Integer productId;
private LssgProductClass lssgProductClass;
private String productName;
private Date productUpTime;
private Date productDownTime;
private String productPhoto;
private String smallPhoto;
private String bigPhoto;
private BigDecimal productMarketPrice;
private BigDecimal productMallPrice;
private Integer productNum;
private Integer soldNum;
private BigDecimal productWeight;
private BigDecimal promotePrice;
private Date promoteStartDate;
private Date promoteEndDate;
private BigDecimal fregiht;
private Integer isBest;
private Integer isNew;
private Integer isHot;
private Integer isSpecial;
private Integer isState;
private String productAddr;
private String productNotes;
private String productEffect;
private static final long serialVersionUID = 1L;
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public Date getProductUpTime() {
return productUpTime;
}
public void setProductUpTime(Date productUpTime) {
this.productUpTime = productUpTime;
}
public Date getProductDownTime() {
return productDownTime;
}
public void setProductDownTime(Date productDownTime) {
this.productDownTime = productDownTime;
}
public String getProductPhoto() {
return productPhoto;
}
public void setProductPhoto(String productPhoto) {
this.productPhoto = productPhoto;
}
public String getSmallPhoto() {
return smallPhoto;
}
public void setSmallPhoto(String smallPhoto) {
this.smallPhoto = smallPhoto;
}
public String getBigPhoto() {
return bigPhoto;
}
public void setBigPhoto(String bigPhoto) {
this.bigPhoto = bigPhoto;
}
public BigDecimal getProductMarketPrice() {
return productMarketPrice;
}
public void setProductMarketPrice(BigDecimal productMarketPrice) {
this.productMarketPrice = productMarketPrice;
}
public BigDecimal getProductMallPrice() {
return productMallPrice;
}
public void setProductMallPrice(BigDecimal productMallPrice) {
this.productMallPrice = productMallPrice;
}
public Integer getProductNum() {
return productNum;
}
public void setProductNum(Integer productNum) {
this.productNum = productNum;
}
public Integer getSoldNum() {
return soldNum;
}
public void setSoldNum(Integer soldNum) {
this.soldNum = soldNum;
}
public BigDecimal getProductWeight() {
return productWeight;
}
public void setProductWeight(BigDecimal productWeight) {
this.productWeight = productWeight;
}
public BigDecimal getPromotePrice() {
return promotePrice;
}
public void setPromotePrice(BigDecimal promotePrice) {
this.promotePrice = promotePrice;
}
public Date getPromoteStartDate() {
return promoteStartDate;
}
public void setPromoteStartDate(Date promoteStartDate) {
this.promoteStartDate = promoteStartDate;
}
public Date getPromoteEndDate() {
return promoteEndDate;
}
public void setPromoteEndDate(Date promoteEndDate) {
this.promoteEndDate = promoteEndDate;
}
public BigDecimal getFregiht() {
return fregiht;
}
public void setFregiht(BigDecimal fregiht) {
this.fregiht = fregiht;
}
public Integer getIsBest() {
return isBest;
}
public void setIsBest(Integer isBest) {
this.isBest = isBest;
}
public Integer getIsNew() {
return isNew;
}
public void setIsNew(Integer isNew) {
this.isNew = isNew;
}
public Integer getIsHot() {
return isHot;
}
public void setIsHot(Integer isHot) {
this.isHot = isHot;
}
public Integer getIsSpecial() {
return isSpecial;
}
public void setIsSpecial(Integer isSpecial) {
this.isSpecial = isSpecial;
}
public Integer getIsState() {
return isState;
}
public void setIsState(Integer isState) {
this.isState = isState;
}
public String getProductAddr() {
return productAddr;
}
public void setProductAddr(String productAddr) {
this.productAddr = productAddr;
}
public String getProductNotes() {
return productNotes;
}
public void setProductNotes(String productNotes) {
this.productNotes = productNotes;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public LssgProductClass getLssgProductClass() {
return lssgProductClass;
}
public void setLssgProductClass(LssgProductClass lssgProductClass) {
this.lssgProductClass = lssgProductClass;
}
public String getProductEffect() {
return productEffect;
}
public void setProductEffect(String productEffect) {
this.productEffect = productEffect;
}
}
LssgProductClass 实体类
package com.lianwei.lssg.entity;
import java.io.Serializable;
public class LssgProductClass implements Serializable {
private Integer productClassId;
private String productClassName;
private String productIsShow;
private String productDescription;
public Integer getProductClassId() {
return productClassId;
}
public void setProductClassId(Integer productClassId) {
this.productClassId = productClassId;
}
public String getProductClassName() {
return productClassName;
}
public void setProductClassName(String productClassName) {
this.productClassName = productClassName;
}
public String getProductIsShow() {
return productIsShow;
}
public void setProductIsShow(String productIsShow) {
this.productIsShow = productIsShow;
}
public String getProductDescription() {
return productDescription;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
@Override
public String toString() {
return "LssgProductClass{" +
"productClassId=" + productClassId +
", productClassName='" + productClassName + '\'' +
", productIsShow='" + productIsShow + '\'' +
", productDescription='" + productDescription + '\'' +
'}';
}
}
从而得到LssgCart实体类(这里以代码实体类名来说明)
/*
Created by IntelliJ IDEA.
User: Kalvin
Date: 2020/5/11
Time: 22:49
*/
package com.lianwei.lssg.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
public class LssgCart implements Serializable {
private Map<String, LssgCartItem> cartItems = new HashMap<String, LssgCartItem>();
private BigDecimal totalPrice;
public Map<String, LssgCartItem> getCartItems() {
return cartItems;
}
public void setCartItems(Map<String, LssgCartItem> cartItems) {
this.cartItems = cartItems;
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
}
创建LssgCartItem实体类
/*
Created by IntelliJ IDEA.
User: Kalvin
Date: 2020/5/12
Time: 10:59
*/
package com.lianwei.lssg.entity;
import java.io.Serializable;
import java.math.BigDecimal;
public class LssgCartItem implements Serializable {
private LssgProduct lssgProduct;
private BigDecimal buyNum; //购买总重量
private BigDecimal subtotalPrice;
private String cartState; //商品库存状态(无货、有货、补货中)
public LssgCartItem() {
}
public LssgCartItem(LssgProduct lssgProduct, BigDecimal buyNum, BigDecimal subtotalPrice, String cartState) {
this.lssgProduct = lssgProduct;
this.buyNum = buyNum;
this.subtotalPrice = subtotalPrice;
this.cartState = cartState;
}
public LssgProduct getLssgProduct() {
return lssgProduct;
}
public void setLssgProduct(LssgProduct lssgProduct) {
this.lssgProduct = lssgProduct;
}
public BigDecimal getBuyNum() {
return buyNum;
}
public void setBuyNum(BigDecimal buyNum) {
this.buyNum = buyNum;
}
public BigDecimal getSubtotalPrice() {
return subtotalPrice;
}
public void setSubtotalPrice(BigDecimal subtotalPrice) {
this.subtotalPrice = subtotalPrice;
}
public String getCartState() {
return cartState;
}
public void setCartState(String cartState) {
this.cartState = cartState;
}
}
到这我们就完成了购物车实体设计,主要明白购物车、购物项、商品三者之间的关系