📄 cartitem.java
字号:
/**
*
*/
package com.eshop.vo;
import java.math.BigDecimal;
import com.eshop.vo.Item;
/**
* 购物车中的每项商品
* @author jonson
*
*/
public class CartItem {
/* 私有字段 */
private Item item;//商品
private int quantity;//数量
private BigDecimal total;//总价格
/* JavaBeans 属性 */
public BigDecimal getTotal() {
return total;
}
public Item getItem() {
return item;
}
/**设置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 */
/** 增加item的数量**/
public void incrementQuantity() {
quantity++;
calculateTotal();
}
/**
* 计算item的金额
*/
private void calculateTotal() {
if (item != null && item.getListprice() !=0.0f) {
total = new BigDecimal(item.getListprice()).multiply(new BigDecimal(quantity));
} else {
total = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -