• 大小: 18.78MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-04
  • 语言: Java
  • 标签: java  web  

资源简介

适合电商用户参考,适合刚接触电商的朋友们做参考示例

资源截图

代码片段和文件信息

package com.softeem.jingdong.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.softeem.jingdong.entity.GoodsBean;
import com.softeem.jingdong.entity.ShoppingCarBean;
import com.softeem.jingdong.entity.UsersBean;
import com.softeem.jingdong.service.GoodsService;
import com.softeem.jingdong.service.ShoppingCarService;

/***
 * 商品信息
 * @author Administrator
 *
 */
public class GoodsAction extends ActionSupport {

private static final long serialVersionUID = 8979942382300596390L;
private GoodsService goodsService;
private ShoppingCarService scs;
private int id;
private List list = new ArrayList();
private GoodsBean goods = new GoodsBean();
private String key;

/**
 * 用户首页商品列表
 */
public String getGoodsList(){
//调用方法获取商品集合
list = goodsService.getAllGoods();
return SUCCESS; 
}

/**
 * 查看商品详细信息
 * @return
 */
public String getGoodsInfo(){
goods = goodsService.getGoodsById(id);
return SUCCESS;
}

/**
 * 购买商品
 * @return
 */
public String buyGoods(){

//获取 Session 
HttpSession session = ServletActionContext.getRequest().getSession(true);

//获取用户
UsersBean users = (UsersBean)session.getAttribute(“users“);

//获取用户的购物车信息
ShoppingCarBean shoppingCar = users.getShoppingCar();

//将商品添加到购物车里面
GoodsBean goods = scs.addGoodsToShoppingCar(id);
shoppingCar.getList().add(goods);

//设置购物车总价
shoppingCar.setSumPrice( this.getShoppingCarSumPrice( shoppingCar.getList() ) );

//设置商品总数量
shoppingCar.setNumber( shoppingCar.getList().size() );

return SUCCESS;
}

/**
 * 求购物车总价
 */
public double getShoppingCarSumPrice(List list){

double sum = 0;

for(GoodsBean g : list){
sum += g.getPrice();
}

return sum;
}

/**
 * 模糊查询商品
 * @return
 */
public String getSearchGoodsList(){
list = goodsService.getSearchList(key);
return SUCCESS;
}


public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public GoodsBean getGoods() {
return goods;
}
public void setGoods(GoodsBean goods) {
this.goods = goods;
}

public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public void setGoodsService(GoodsService goodsService) {
this.goodsService = goodsService;
}
public void setScs(ShoppingCarService scs) {
this.scs = scs;
}
public GoodsService getGoodsService() {
return goodsService;
}
public ShoppingCarService getScs() {
return scs;
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-03-20 21:04  JingDongSSH\
     文件        2872  2014-03-20 21:08  JingDongSSH\.classpath
     目录           0  2014-03-20 21:23  JingDongSSH\.myeclipse\
     文件         309  2014-03-20 21:08  JingDongSSH\.mymetadata
     文件        1417  2014-01-01 17:20  JingDongSSH\.project
     目录           0  2014-03-20 21:04  JingDongSSH\.settings\
     文件         500  2014-01-01 17:21  JingDongSSH\.settings\.jsdtscope
     文件        1040  2014-01-01 19:02  JingDongSSH\.settings\com.genuitec.eclipse.j2eedt.core.prefs
     文件         106  2014-03-20 13:10  JingDongSSH\.settings\org.eclipse.core.resources.prefs
     文件         330  2014-01-01 17:21  JingDongSSH\.settings\org.eclipse.jdt.core.prefs
     文件          49  2014-01-01 17:21  JingDongSSH\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2014-01-01 17:21  JingDongSSH\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2014-03-20 21:13  JingDongSSH\WebRoot\
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\meta-INF\
     文件          36  2014-01-01 17:20  JingDongSSH\WebRoot\meta-INF\MANIFEST.MF
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\
     文件        3913  2014-01-01 19:08  JingDongSSH\WebRoot\WEB-INF\classes\applicationContext.xml
     文件        2359  2014-01-01 17:21  JingDongSSH\WebRoot\WEB-INF\classes\applicationContext_beans.xml
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\com\
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\action\
     文件        4531  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\action\GoodsAction.class
     文件        3745  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\action\OrderAction.class
     文件        1811  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\action\ShoppingCarAction.class
     文件        3464  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\action\UsersAction.class
     目录           0  2014-03-20 21:04  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\dao\
     文件         466  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\dao\GoodsDao.class
     文件         186  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\dao\OrderDao.class
     文件         295  2014-03-20 13:14  JingDongSSH\WebRoot\WEB-INF\classes\com\softeem\jingdong\dao\UsersDao.class
............此处省略267个文件信息

评论

共有 条评论