用STRUTS ,HIBERNATE, SPRING 三种框架整合做的实战项目
源代码在线查看: control.java
package com.ghy.data.order;
import java.util.ArrayList;
public class Control {
public ArrayList addGoods(OrderItem orderItem , ArrayList arrayList) {
if (arrayList.size()==0) {
arrayList.add(orderItem);
}
else {
boolean find = false;
for (int i = 0; i < arrayList.size(); i++) {
OrderItem orderItem1 = (OrderItem) arrayList.get(i);
// 如果存在直接修改购物车中相应物品信息
if (orderItem1.getBookid().equals(orderItem.getBookid())) {
// 修改数量
orderItem1.setAmount(orderItem1.getAmount() + 1);
// 修改总价
orderItem1.setSubtotal();
// 更新该物品信息
arrayList.set(i, orderItem1);
find = true;
break;
}
}
// 如果不存在,则添加这个物品
if (!find) {
arrayList.add(orderItem);
}
}
return arrayList ;
}
//第一个参数为FORM过来的集合,第二个参数为CART过来的集合
public ArrayList updateGoods(ArrayList listFromOrder , ArrayList listFromCart) {
OrderItem orderItem1 ;
OrderItem orderItem2 ;
ArrayList arrayList = new ArrayList();
for (int i = 0; i < listFromCart.size(); i++)
{
orderItem1 = (OrderItem)listFromOrder.get(i);
orderItem2 = (OrderItem)listFromCart.get(i);
if(orderItem1.getChecked()==null)
{
orderItem2.setAmount(orderItem1.getAmount());
orderItem2.setSubtotal();
arrayList.add(orderItem2);
}
}
return arrayList ;
}
}