通过重写Object类hashCode 和equals方法,来修改生成新对象时的规则,如果符合我的规则,那么你new出来的两个对象就是一个对象!
2016-12-19
加了个显示库存,购买数量不能大于库存数量:
1. JSP部分:
<td>购买数量:<span id="sub" onclick="sub();">-</span><input type="text" id="number" name="number" value="1" size="2"/><span id="add" onclick="add();">+</span>
<em id="inventory">库存<%=item.getNumber() %>件</em>
</td>
1. JSP部分:
<td>购买数量:<span id="sub" onclick="sub();">-</span><input type="text" id="number" name="number" value="1" size="2"/><span id="add" onclick="add();">+</span>
<em id="inventory">库存<%=item.getNumber() %>件</em>
</td>
2016-12-15
//remove goods from cart
public boolean removeGoodsFromCart(Items item,int number) {
if (number>=goods.get(item)) {
goods.remove(item);
} else {
goods.put(item,goods.get(item)-number);
}
caculaterTotalPrice();
return true;
}
public boolean removeGoodsFromCart(Items item,int number) {
if (number>=goods.get(item)) {
goods.remove(item);
} else {
goods.put(item,goods.get(item)-number);
}
caculaterTotalPrice();
return true;
}
2016-12-15
//add goods to cart
public boolean addGoodsInCart(Items item,int number) {
if (goods.containsKey(item)) {
goods.put(item, goods.get(item)+number);
} else {
goods.put(item, number);
}
caculaterTotalPrice();
return true;
}
public boolean addGoodsInCart(Items item,int number) {
if (goods.containsKey(item)) {
goods.put(item, goods.get(item)+number);
} else {
goods.put(item, number);
}
caculaterTotalPrice();
return true;
}
2016-12-15