• 大小: 11.24MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2024-02-21
  • 语言: 其他
  • 标签: ssh  网上书店  

资源简介

很适合初学者 tomcat6.0 MyEclipse6.5 jdk1.6

资源截图

代码片段和文件信息

package com.org.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.org.model.Book;
import com.org.model.ShopCart;
import com.org.service.*;
import java.util.*;
public class BasketAction extends ActionSupport {
private List basket;
private int bookid=-1;
private int booknum=0;
private String isdelete=““;
private float allprice=0f;
private String orderid=““;
private ShopCart shopcart;
//需要注入的图书操作属性bookcontrol
private BookDetailControl bookcontrol;
/**
 * 通过setter,由Spring容器为bookcontrol属性
 * 注入BookDetailControl组件
 * @param bookcontrol
 */
public void setBookcontrol(BookDetailControl bookcontrol) {
this.bookcontrol = bookcontrol;
}

/**
 * 添加到购物车方法,判断购物车是否已经存在物品,
 * 是则追加,并判断是否重复
 *   
 * @return
 * @throws Exception
 */
public String BuyBook() throws Exception {
Map session = ActionContext.getContext().getSession();
List b=null;
//如果物品编号不等于默认值,则表示新添加一种物品
if(this.getBookid()!=-1){
//将要添加的物品查询出来
List books=bookcontrol.SearchBooks(this.getBookid());
List shop=new linkedList();
ShopCart shopcart=new ShopCart();
Book boo=(Book)books.get(0);
//将查询出来的物品的编号和名称放入购物车
shopcart.setBookid(boo.getBookid());
shopcart.setBookname(boo.getBookname());
shop.add(0shopcart);

//如果购物车已经有物品,则一起添加
if(session.get(“basket“)!=null){
b=(List)session.get(“basket“);
//判断物品是否已经存在相同物品
boolean is=false;
for(ListIterator iterator=b.listIterator();iterator.hasNext();) {
ShopCart book= (ShopCart) iterator.next();
if(book.getBookid()==this.getBookid()){
is=true;
//System.out.println(“物品“+book.getBookname()+“已经存在“);
}
}
//不存在相同物品
if(!is){
//System.out.println(“可以添加物品“+this.getBookid());
//在原有基础上将新物品()添加到b这个List中
b.addAll(shop);
}
//将List添加到session真正将物品添加到购物车
session.put(“basket“b);
}
//第一次添加物品到购物车
else {
session.put(“basket“shop);
}
return SUCCESS;
}
return SUCCESS;
}

/**
 * 显示购物车物品,结算总价
 * @return
 */
public String SetOrder() throws Exception {
Map session = ActionContext.getContext().getSession();
//显示购物车
if(session.get(“basket“)!=null) {
List b=(List)session.get(“basket“);
//在循环中计算图书总价
for(ListIterator iterator=b.listIterator();iterator.hasNext();) {
ShopCart shopcart= (ShopCart) iterator.next();
//设置订单编号由用户名和时间组成
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat();
orderid=session.get(“username“).toString()+“-“+sdf.format(new Date());
shopcart.setOrderid(orderid);
//计算一种书的总价
float price=shopcart.getCount()*getOnePrice(shopcart.getBookid());
shopcart.setPrice(price);
//计算所有书的总结
allprice+=shopcart.getPrice();
}
basket=(List)session.get(“basket“);
}
return SUCCESS;
}

/**
 * 获取指定编号的书籍的单

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        463  2008-05-16 21:33  Bookshop\.classpath

     文件        297  2010-09-01 14:45  Bookshop\.mymetadata

     文件        853  2008-05-16 21:33  Bookshop\.project

     文件        330  2008-05-16 21:33  Bookshop\.settings\org.eclipse.jdt.core.prefs

     文件        288  2008-05-16 21:33  Bookshop\.settings\org.eclipse.jst.common.project.facet.core.prefs

     文件        444  2008-05-16 21:33  Bookshop\.settings\org.eclipse.wst.common.component

     文件        269  2008-05-16 21:33  Bookshop\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件        588  2008-05-22 18:04  Bookshop\build\classes\Book.hbm.xml

     文件        430  2008-05-17 00:30  Bookshop\build\classes\BookType.hbm.xml

     文件       3442  2010-09-01 14:46  Bookshop\build\classes\com\org\action\BasketAction.class

     文件        689  2010-09-01 14:46  Bookshop\build\classes\com\org\action\interceptor\AdminLoginInterceptor.class

     文件       2870  2010-09-01 14:46  Bookshop\build\classes\com\org\action\LoginAction.class

     文件       2837  2010-09-01 14:46  Bookshop\build\classes\com\org\action\OrderBookAction.class

     文件       2549  2010-09-01 14:46  Bookshop\build\classes\com\org\action\ShowBooksAction.class

     文件        574  2010-09-01 14:46  Bookshop\build\classes\com\org\dao\BookDetailDao.class

     文件       2159  2010-09-01 14:46  Bookshop\build\classes\com\org\dao\hibernate\BookDetailDaoHibernate.class

     文件       1391  2010-09-01 14:46  Bookshop\build\classes\com\org\dao\hibernate\UserDaoHibernate.class

     文件        316  2010-09-01 14:46  Bookshop\build\classes\com\org\dao\UserDao.class

     文件       1165  2010-09-01 14:46  Bookshop\build\classes\com\org\filter\EncodingFilter.class

     文件       1447  2010-09-01 14:46  Bookshop\build\classes\com\org\filter\SetCharacterEncodingFilter.class

     文件       1963  2010-09-01 14:46  Bookshop\build\classes\com\org\model\Book.class

     文件        768  2010-09-01 14:46  Bookshop\build\classes\com\org\model\BookType.class

     文件       2321  2010-09-01 14:46  Bookshop\build\classes\com\org\model\Order.class

     文件       1523  2010-09-01 14:46  Bookshop\build\classes\com\org\model\ShopCart.class

     文件        954  2010-09-01 14:46  Bookshop\build\classes\com\org\model\User.class

     文件        684  2010-09-01 14:46  Bookshop\build\classes\com\org\service\BookDetailControl.class

     文件       2485  2010-09-01 14:46  Bookshop\build\classes\com\org\service\impl\BookDetailControlImpl.class

     文件       1138  2010-09-01 14:46  Bookshop\build\classes\com\org\service\impl\UserControlImpl.class

     文件        235  2010-09-01 14:46  Bookshop\build\classes\com\org\service\UserControl.class

     文件        616  2008-05-21 01:08  Bookshop\build\classes\Order.hbm.xml

............此处省略116个文件信息

评论

共有 条评论