package com.bookstore.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
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.bookstore.domain.CartItem;
import com.bookstore.domain.ShoppingCart;
import com.bookstore.service.ShoppingCartService;
@Controller
public class CartController {
@Autowired
private ShoppingCartService shoppingCartService;
@RequestMapping(value = "addtoCart.action")
public String addCart(String id, HttpServletResponse response,
HttpServletRequest request,HttpSession session) {
String cookievalue = "null";
ShoppingCart sc = new ShoppingCart();
Cookie[] cookies = request.getCookies();
Cookie cookie = shoppingCartService.cookieSearch(cookies);
byte[] by = null;
if (cookie != null) {
cookievalue = Base64.encodeBase64String(shoppingCartService
.addShoppingCart(cookie, id).getBytes());
cookie.setValue(cookievalue);
cookie.setMaxAge(60 * 60 * 24 * 6);// 设置cookie过期时间为6天
response.addCookie(cookie);
by = Base64.decodeBase64(cookie.getValue().getBytes());
} else {
Cookie newcookie = new Cookie("shoppingcart", "initial");
String cookievalue2 = Base64.encodeBase64String(shoppingCartService
.addShoppingCart(newcookie, id).getBytes());
newcookie.setValue(cookievalue2);
newcookie.setMaxAge(60 * 60 * 24 * 6);// 设置cookie过期时间为6天
response.addCookie(newcookie);
by = Base64.decodeBase64(newcookie.getValue().getBytes());
}
// 将cookie中的值转换成对象准备回传。
JSONObject scc = JSONObject.fromObject(new String(by));
ShoppingCart shopcart = (ShoppingCart) JSONObject.toBean(scc,
ShoppingCart.class);
session.setAttribute("shoppingcart2", shopcart);
List<CartItem> cartItem = shoppingCartService.generateCartItem(shopcart);
session.setAttribute("cartItem", cartItem);
return "cart";
}
// 跳转购物车
@RequestMapping(value = "/cart")
public String cart(HttpSession session) {
if(session.getAttribute("shoppingcart2")!=null)
{
ShoppingCart shopcart=(ShoppingCart) session.getAttribute("shoppingcart2");
List<CartItem> cartItem = shoppingCartService.generateCartItem(shopcart);
session.setAttribute("cartItem", cartItem);
}
return "cart";
}
@RequestMapping(value="/addGoods")
public void addGoods(HttpServletRequest request,HttpServletResponse response,HttpSession session,String id) throws IOException
{
Cookie[] cookies = request.getCookies();
Cookie cookie = shoppingCartService.cookieSearch(cookies);
String cookievalue = Base64.encodeBase64String(shoppingCartService
.addShoppingCart(cookie, id).getBytes());
cookie.setValue(cookievalue);
cookie.setMaxAge(60 * 60 * 24 * 6);// 设置cookie过期时间为6天
response.addCookie(cookie);
byte [] by =Base64.decodeBase64(cookie.getValue().getBytes());
JSONObject scc = JSONObject.fromObject(new String(by));
ShoppingCart shopcart = (ShoppingCart) JSONObject.toBean(scc,
ShoppingCart.class);
session.setAttribute("shoppingcart2", shopcart);
List<CartItem> cartItem = shoppingCartService.generateCartItem(shopcart);
session.setAttribute("cartItem", cartItem);
//return null;
}
@RequestMapping(value="/subGoods")
public void subGoods(HttpServletRequest request,HttpServletResponse response,HttpSession session,String id) throws IOException
{
Cookie[] cookies = request.getCookies();
Cookie cookie = shoppingCartService.cookieSearch(cookies);
String cookievalue = Base64.encodeBase64String(shoppingCartService
.subShoppingCart(cookie, id).getBytes());
cookie.setValue(cookievalue);
cookie.setMaxAge(60 * 60 * 24 * 6);// 设置cookie过期时间为6天
response.addCookie(cookie);
byte [] by =Base64.decodeBase64(cookie.getValue().getBytes());
JSONObject scc = JSONObject.fromObject(new String(by));
ShoppingCart shopcart = (ShoppingCart) JSONObject.toBean(scc,
ShoppingCart.class);
session.setAttribute("shoppingcart2", shopcart);
List<CartItem> cartItem = shoppingCartService.generateCartItem(shopcart);
session.setAttribute("cartItem", cartItem);
//return null;
}
@RequestMapping(value="/removeGoods")
public String removeGoods(HttpServletRequest request,HttpServletResponse response,HttpSession session,String id)
{
Cookie[] cookies = request.getCookies();
Cookie cookie = shoppingCartService.cookieSearch(cookies);
String cookievalue = Base64.encodeBase64String(shoppingCartService
.subShoppingCartById(cookie, id).getBytes());
cookie.setValue(cookievalue);
cookie.setMaxAge(60 * 60 * 24 * 6);// 设置cookie过期时间为6天
response.addCookie(cookie);
byte [] by =Base64.decodeBase64(cookie.getValue().getBytes());
JSONObject scc = JSONObject.fromObject(new String(by));
ShoppingCart shopcart = (ShoppingCart) JSONObject.toBean(scc,ShoppingCart.class);
session.setAttribute("shoppingcart2", shopcart);
List<CartItem> cartItem = shoppingCartService.generateCartItem(shopcart);
session.setAttribute("cartItem", cartItem);
return "cart";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
个人花大量时间整理出的真实毕业设计实战成果,内容丰富,文档也很详细。无论做毕业设计还是用于学习技能,或工作中当做参考资料,都能发挥重要作用 亲们下载我任何一个付费资源后,即可私信联系我免费下载其他相关资源哦~ 个人花大量时间整理出的真实毕业设计实战成果,内容丰富,文档也很详细。无论做毕业设计还是用于学习技能,或工作中当做参考资料,都能发挥重要作用 亲们下载我任何一个付费资源后,即可私信联系我免费下载其他相关资源哦~ 个人花大量时间整理出的真实毕业设计实战成果,内容丰富,文档也很详细。无论做毕业设计还是用于学习技能,或工作中当做参考资料,都能发挥重要作用 亲们下载我任何一个付费资源后,即可私信联系我免费下载其他相关资源哦~
资源推荐
资源详情
资源评论
收起资源包目录
《毕业设计》--仿京东商城毕业设计.zip (218个子文件)
ShoppingCartServiceImpl.class 6KB
CartController.class 5KB
UserController.class 4KB
GoodsController.class 3KB
GoodsServiceImpl.class 3KB
RegistUserVo.class 3KB
Goods.class 2KB
User.class 2KB
UserServiceImpl.class 2KB
CartItem.class 2KB
FeedBackController.class 2KB
FeedBack.class 1KB
ShoppingCart.class 1KB
PageController.class 1KB
FeedBackServiceImpl.class 952B
ShoppingCartService.class 734B
GoodsService.class 573B
GoodsMapper.class 532B
UserService.class 421B
UserMapper.class 363B
PageUtil.class 343B
FeedBackService.class 311B
FeedBackMapper.class 305B
.classpath 716B
org.eclipse.wst.common.component 540B
org.eclipse.wst.jsdt.ui.superType.container 49B
myaccount.css 8KB
content.css 3KB
contact.css 3KB
details.css 2KB
register.css 2KB
special.css 2KB
cart.css 2KB
feedback.css 1KB
index.css 1KB
header.css 1KB
books.css 1KB
about.css 1KB
login.css 957B
footer.css 738B
footer_bg.gif 12KB
about.gif 10KB
center_bg.gif 8KB
loading.gif 3KB
border.gif 2KB
logo.gif 2KB
special_icon.gif 2KB
new_icon.gif 2KB
flag.gif 2KB
order_now.gif 2KB
promo_icon.gif 2KB
zoom.gif 2KB
cart_thumb.gif 2KB
csscreme.gif 2KB
prevlabel.gif 1KB
nextlabel.gif 1KB
bullet4.gif 1KB
bullet5.gif 1KB
bullet3.gif 1KB
bullet1.gif 1KB
bullet2.gif 1KB
bullet6.gif 1KB
closelabel.gif 979B
footer_logo.gif 723B
banner.gif 595B
new_prod_box.gif 556B
register_bt.gif 556B
contact_bt.gif 487B
gb.gif 382B
fr.gif 366B
de.gif 362B
prev.gif 307B
next.gif 305B
left_menu_bullet.gif 281B
box_bottom.gif 262B
box_top.gif 262B
cart.gif 260B
close.gif 222B
box_center.gif 93B
color3.gif 55B
color2.gif 55B
color1.gif 55B
blank.gif 43B
aspectjweaver-1.6.11.jar 1.61MB
spring-core-3.2.0.RELEASE.jar 843KB
spring-context-3.2.0.RELEASE.jar 834KB
jackson-mapper-asl-1.9.11.jar 762KB
mybatis-3.2.7.jar 696KB
javassist-3.17.1-GA.jar 695KB
mysql-connector-java-5.1.7-bin.jar 693KB
log4j-core-2.0-rc1.jar 686KB
spring-webmvc-3.2.0.RELEASE.jar 621KB
spring-web-3.2.0.RELEASE.jar 610KB
c3p0-0.9.1.2.jar 596KB
spring-beans-3.2.0.RELEASE.jar 591KB
commons-collections-3.2.1.jar 562KB
log4j-1.2.17.jar 478KB
hibernate-validator-4.3.0.Final.jar 465KB
spring-test-3.2.0.RELEASE.jar 441KB
jstl-1.2.jar 405KB
共 218 条
- 1
- 2
- 3
资源评论
季风泯灭的季节
- 粉丝: 1901
- 资源: 3370
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功