📄 cartitem.java
字号:
package com.jspdev.cart;
import java.io.*;
import java.math.*;
import com.jspdev.vo.*;
/**
*代表了购物车中各个item的信息
*/
public class CartItem implements Serializable {
/* Private Fields */
private Item item;
private int quantity;
private boolean inStock;
private BigDecimal total;
/* JavaBeans Properties */
public boolean isInStock() { return inStock; }
public void setInStock(boolean inStock) { this.inStock = inStock; }
public BigDecimal getTotal() { return total; }
public Item getItem() { return item; }
public void setItem(Item item) {
this.item = item;
calculateTotal();
}
public int getQuantity() { return quantity; }
public void setQuantity(int quantity) {
this.quantity = quantity;
calculateTotal();
}
/* Public methods */
public void incrementQuantity() {
quantity++;
calculateTotal();
}
/**
* 计算item的金额
*/
private void calculateTotal() {
if (item != null && item.getListPrice() != null) {
total = item.getListPrice().multiply(new BigDecimal(quantity));
} else {
total = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -