cartitemform.java
来自「使用jsp+Servlet,采用MVC模式,实现了一典型小型电子商务网站的全过程」· Java 代码 · 共 67 行
JAVA
67 行
/**
*
*/
package com.eshop.form;
import java.math.BigDecimal;
import com.eshop.vo.Item;
/**
* @author jonson
*
*/
public class CartItemForm {
/* 私有字段 */
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 + =
减小字号Ctrl + -
显示快捷键?