资源简介
java培训课程的一个案例:当当网。框架:ssm。用eclipse开发。前台用jsp写的。包含功能:展示、轮播图、分页、购买、购物车、订单等功能
代码片段和文件信息
package com.sjl.controller;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjl.entity.CartItem;
import com.sjl.service.CartService;
@Controller
@RequestMapping(“/cart“)
public class CartController {
@Resource(name=“cartService“)
private CartService service;
@RequestMapping(“/showCarts.do“)
public String cartList(Model modelHttpServletRequest request) {
HttpSession session = request.getSession();
//获取session中的购物车
List items = (List)session.getAttribute(“cart“);
model.addAttribute(“items“ items);
//此处不能写Double sumDang = null;不然会报空指针异常
Double sumDang = 0.0;
Double save= 0.0;
for(CartItem c:items) {
if(c!=null) {
sumDang +=c.getPro().getDangPrice()*c.getQty();
save +=(c.getPro().getFixedPrice()-c.getPro().getDangPrice())*c.getQty();
}
}
Map map = new HashMap();
map.put(“save“ save);
map.put(“sumDang“ sumDang);
model.addAttribute(“map“ map);
return “cart/cart_list“;
}
/**
* 变更商品的数量
* @param change 更改后的商品数量
* @param pid 商品的id
* @param request
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping(“/change.do“)
@ResponseBody
public boolean changeQty(Integer idInteger changeNumHttpServletRequest request) throws UnsupportedEncodingException {
request.setCharacterEncoding(“utf-8“);
System.out.println(changeNum+“***********“+id);
HttpSession session = request.getSession();
List items = (List)session.getAttribute(“cart“);
for(CartItem ca:items) {
if(id==ca.getPro().getId()) {
ca.setQty(changeNum);
break;
}
}
session.setAttribute(“items“ items);
return true;
}
@RequestMapping(“/recovery.do“)
@ResponseBody
public boolean recovery(Integer idHttpServletRequest request) {
HttpSession session = request.getSession();
List items = (List)session.getAttribute(“cart“);
List ditems = (List)session.getAttribute(“ditems“);
//新建一个集合,将恢复的元素添加进去
List ritems = new ArrayList<>();
for(CartItem ca:ditems) {
if(id==ca.getPro().getId()) {
items.add(ca);
ritems.add(ca);
}
}
ditems.removeAll(ritems);
session.setAttribute(“items“ items);
session.setAttribute(“ditems“ ditems);
return true;
}
@RequestMapping(“/delete.do“)
@ResponseBody
public boolean delete(Integer idHttpServletRequest request) {
HttpSession session = request.getSession();
List items = (List
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-15 21:12 dang\
文件 3928 2018-03-27 13:16 dang\.classpath
文件 904 2018-03-27 13:02 dang\.project
目录 0 2018-05-15 21:12 dang\.settings\
文件 567 2018-03-27 13:02 dang\.settings\.jsdtscope
文件 364 2018-03-27 13:02 dang\.settings\org.eclipse.jdt.core.prefs
文件 464 2018-03-27 13:02 dang\.settings\org.eclipse.wst.common.component
文件 345 2018-03-27 13:02 dang\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2018-03-27 13:02 dang\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2018-03-27 13:02 dang\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2018-05-15 21:12 dang\build\
目录 0 2018-05-15 21:12 dang\build\classes\
文件 3754 2018-04-04 09:56 dang\build\classes\applicationContext.xm
目录 0 2018-05-15 21:12 dang\build\classes\com\
目录 0 2018-05-15 21:12 dang\build\classes\com\sjl\
目录 0 2018-05-15 21:12 dang\build\classes\com\sjl\controller\
文件 5553 2018-05-15 21:06 dang\build\classes\com\sjl\controller\CartController.class
文件 7602 2018-05-15 21:06 dang\build\classes\com\sjl\controller\MainController.class
文件 6852 2018-05-15 21:06 dang\build\classes\com\sjl\controller\UserController.class
目录 0 2018-05-15 21:12 dang\build\classes\com\sjl\dao\
文件 1798 2018-05-15 21:06 dang\build\classes\com\sjl\dao\BookDao.class
文件 968 2018-05-15 21:06 dang\build\classes\com\sjl\dao\CategoryDao.class
文件 535 2018-05-15 21:06 dang\build\classes\com\sjl\dao\CategoryProductDao.class
文件 952 2018-05-15 21:06 dang\build\classes\com\sjl\dao\UserDao.class
目录 0 2018-05-15 21:12 dang\build\classes\com\sjl\entity\
文件 6271 2018-05-15 21:06 dang\build\classes\com\sjl\entity\Book.class
文件 794 2018-05-15 21:06 dang\build\classes\com\sjl\entity\CartItem.class
文件 3935 2018-05-15 21:06 dang\build\classes\com\sjl\entity\Category.class
文件 2285 2018-05-15 21:06 dang\build\classes\com\sjl\entity\CategoryProduct.class
文件 3223 2018-05-15 21:06 dang\build\classes\com\sjl\entity\Condition.class
文件 3863 2018-05-15 21:06 dang\build\classes\com\sjl\entity\Item.class
............此处省略529个文件信息
- 上一篇:JSP+SQl酒店管理系统
- 下一篇:用javaservlet写的卖衣服的购物网站
评论
共有 条评论