📄 cartitem.java
字号:
package com.webshop.domain;
import java.io.*;
import java.math.*;
/**
* @author w
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class CartItem implements Serializable {
/* 私有字段 */
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 + -