基于JSP网上购物系统论文

}

cart.getItems().clear(); //清空购物车 session.put(\ Maprequest=(Map)ServletActionContext.getContext().get(\ request.put(\ return ActionSupport.SUCCESS; } publicStringmyOrder() //根据用户查询订单 { Map session= ServletActionContext.getContext().getSession(); TUser user=(TUser)session.get(\ //获取用户 String sql=\ List orderList=orderDAO.getHibernateTemplate().find(sql); //调用orderDAO中的find方法,执行sql语句 Map

request=(Map)ServletActionContext.getContext().get(\ request.put(\ return ActionSupport.SUCCESS; } public String orderMana() //订单管理 { String sql=\ List orderList=orderDAO.getHibernateTemplate().find(sql); Map

request=(Map)ServletActionContext.getContext().get(\ request.put(\ return ActionSupport.SUCCESS;

} publicStringorderDel() //用户自己删除订单 { TOrder order=orderDAO.findById(orderId); orderDAO.delete(order);

32

Map session= ServletActionContext.getContext().getSession();

TUser user=(TUser)session.get(\ this.setMessage(\删除成功\ this.setPath(\跳转到 myOrder.action return \ } publicStringorderDelByAd() //管理员删除订单 { TOrder order=orderDAO.findById(orderId);

orderDAO.delete(order); String sql=\ orderItemDAO.getHibernateTemplate().bulkUpdate(sql); this.setMessage(\删除成功\ this.setPath(\ return \}

public String orderShouli() //对订单进行受理 { TOrder order=orderDAO.findById(orderId); order.setOrderZhuangtai(\已经受理订单 orderDAO.attachDirty(order); this.setMessage(\受理订单成功\ this.setPath(\ return \}

public String orderDetail() //订单明细 { String sql=\

List

orderItemList=orderItemDAO.getHibernateTemplate().find(sql); for(int i=0;i

33

Map

request=(Map)ServletActionContext.getContext().get(\ request.put(\ return ActionSupport.SUCCESS; }

在cart.java中 package com.util;

import java.util.HashMap; import java.util.Iterator; import java.util.Map;

import com.model.TGoods; import com.model.TOrderItem;

public class Cart //定义购物车类 { protected Map items; public Cart() //定义构造方法 { if (items == null) { items = new HashMap(); } } public void addGoods(Integer goodsId, TOrderItem orderItem) //添加购物车 { if (items.containsKey(goodsId)) {

TOrderItem _orderitem = items.get(goodsId);

_orderitem.setGoodsQuantity(_orderitem.getGoodsQuantity()+

orderItem.getGoodsQuantity()); //如果购买商品重复,则加上数量 items.put(goodsId, _orderitem); } else { items.put(goodsId, orderItem); } }

34

PublicvoiddelGoods(IntegergoodsId)

//删除购物车 { items.remove(goodsId); } public void updateCart(Integer goodsId, int quantity) //更新购物车的数量 { TOrderItem orderItem = items.get(goodsId); orderItem.setGoodsQuantity(quantity); items.put(goodsId, orderItem);

}

public int getTotalPrice() //计算总的价格 { int totalPrice = 0; for (Iterator it = items.values().iterator(); it.hasNext();) { TOrderItem orderItem = (TOrderItem) it.next(); TGoods goods = orderItem.getGoods(); int quantity = orderItem.getGoodsQuantity(); totalPrice += goods.getGoodsTejia() * quantity;

//单价乘以数量 } return totalPrice; } }

商品信息:

<%@ page language=\<%@ taglib prefix=\

<%

String path = request.getContextPath(); %>

35

联系客服:779662525#qq.com(#替换为@)