收藏 分销(赏)

综合项目重点笔记专业资料.doc

上传人:精*** 文档编号:3000887 上传时间:2024-06-12 格式:DOC 页数:16 大小:278.04KB
下载 相关 举报
综合项目重点笔记专业资料.doc_第1页
第1页 / 共16页
综合项目重点笔记专业资料.doc_第2页
第2页 / 共16页
综合项目重点笔记专业资料.doc_第3页
第3页 / 共16页
综合项目重点笔记专业资料.doc_第4页
第4页 / 共16页
综合项目重点笔记专业资料.doc_第5页
第5页 / 共16页
点击查看更多>>
资源描述

1、新巴巴运动网 项目第一天传智.上官云1 课前回顾1、 单点登陆 (搭建环境) 2、 去登陆页面(http:/localhost:8082/login.aspx?return Url = EncodeURLComment(window.location.href)3、 提交登陆(1)顾客名、密码、ReturnUrl)4、 Value=login.aspx ,method=POST GET5、 加密6、 把顾客名保存Redis(Session共享) 1)分析K:V CSESSIONID:USER-Name V:fbb2)SessionProvider ( SessionProviderImpl)

2、手动实例化 (xml配备时间 60分钟)3)保存顾客名到Redis中 7、重定向到之前访问页面8、页面 (登陆、注册、退出,我订单) 分析:页面(动) 静 ajax判断顾客与否登陆页面(前台系统判断顾客与否登陆) ajax 去此外一种系统 返回值被拦截(浏览器)判断程序(单点登陆系统)Ajax 返回值 :jsonjsonp登陆系统(接受String callback) Spring MappingJacksonValue (保存数据 返回JSONP数据) mjv.setJSONFunction(callback); return mjv;(办法返回值处ResponseBody MappingJ

3、acksonValue2 今天内容主打购物车1、 购物车 2、 面向对象设计购物车3、 购物车 非登陆 登陆4、 关闭浏览器还必要在5、 跨电脑或区域购物车还在6、 同款数量追加 同款商品合并7、 排序同窗完毕3 面向对象设计购物车4 加入购物车4.1 设立途径4.2 Controller5 分析购物车Cookie中Session中(Redis) 顾客名(顾客ID)数据库非登陆:商品保存Cookie里 关闭浏览器还在 (七天、一种月)顾客清理Cookie就没了登陆 : Redis 性能比较好 关闭浏览器(不登陆不在) 登陆就在了 (跨区域) 永久保存5.1 Redis保存购物车加入购物车登陆非

4、登陆1:从Request中取Cookies、遍历Cookie 取出之前购物车2:判断Cookie中没有购物车3:有 把购物车中商品添加到Redis购物车中,清理之前Cookie4:没有 5:直接添加当前商品到Redis中购物车里1:从Request中取Cookies、遍历Cookie 取出之前购物车2:判断Cookie中没有购物车3:有 4:没有 创立购物车5:追加当前商品到购物车6:创立Cookie 把新购物车放进去7:保存Cookie写回浏览器去购物车页面判断与否登陆登陆1:从Request中取Cookies、遍历Cookie 取出之前购物车2:再把购物车保存到Redis中,清理Cooki

5、e3:从Redis中取出所有购物车把购物车装满跳转到购物车页面回显购物车内容1:从Request中取Cookies、遍历Cookie 取出之前购物车2:有 购物车数量及SKUID3:没有把购物车装满跳转到购物车页面回显购物车内容购物车(回显数据到购物车页面6 购物车6.1 对象与JSON字符串互转6.2 SkuService入参: SKUID返回值:Sku对象SKu对象(涉及颜色对象、商品对象)商品表SKU表颜色表保存商品到REdis中从Redis中取出购物车6.3 Controller6.3.1 未 优化之前代码package cn.itcast.core.controller;import

6、 java.io.StringWriter;import java.util.List;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springfram

7、ework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import com.fasterxml.jackson.annotation.JsonInclude.Include;import com.fasterxml.jackson.databind.ObjectMapper;import mon.utils.RequestUtils;import mon.web.Constants;import cn.itcast.core.bean.BuyerCart;import cn.itcast.cor

8、e.bean.BuyerItem;import cn.itcast.core.bean.product.Sku;import cn.itcast.core.service.product.SkuService;import cn.itcast.core.service.user.SessionProvider;/* * 购物车 * 去购物车页面 * 添加商品到购物车 * 删除 * + * author lx * */Controllerpublic class CartController Autowiredprivate SessionProvider sessionProvider;/加入

9、购物车RequestMapping(value = /addCart)public String addCart(Long skuId,Integer amount,Model model,HttpServletRequest request,HttpServletResponse response) throws ExceptionObjectMapper om = new ObjectMapper();/不要NULL 不要转了om.setSerializationInclusion(Include.NON_NULL);/声明BuyerCart buyerCart = null;/1:从Re

10、quest中取Cookies、Cookie cookies = request.getCookies();if(null != cookies& cookies.length 0)/遍历Cookie 取出之前购物车for (Cookie cookie :cookies) /2:判断Cookie中没有购物车if(Constants.BUYER_CART.equals(cookie.getName()/转回对象buyerCart = om.readValue(cookie.getValue(),BuyerCart.class);break;/顾客与否登陆String username = sess

11、ionProvider.getAttributeForUsername(RequestUtils.getCSESSIONID(request,response);if(null != username)if(null != buyerCart)/3:有 把购物车中商品添加到Redis购物车中,skuService.insertBuyerCartToRedis(buyerCart,username);/清理之前Cookie4Cookie cookie = new Cookie(Constants.BUYER_CART,null);cookie.setMaxAge(0);cookie.setPat

12、h(/);response.addCookie(cookie);/4:没有 /5:直接添加当前商品到Redis中购物车里/程序未写else/3:有 /4:没有 创立购物车/判断购物车与否为nullif(null = buyerCart)buyerCart = new BuyerCart();/5:追加当前商品到购物车Sku sku = new Sku();/ID sku.setId(skuId);BuyerItem buyerItem = new BuyerItem();buyerItem.setSku(sku);/AmountbuyerItem.setAmount(amount);/追加商品

13、到购物车buyerCart.addItem(buyerItem);/6:创立Cookie 把新购物车放进去StringWriter w = new StringWriter();om.writeValue(w,buyerCart);Cookie cookie = new Cookie(Constants.BUYER_CART,w.toString();/设立时间 写程序1天cookie.setMaxAge(60*60*24);/设立途径 cookie.setPath(/);/上线后 申请域名/7:保存写回浏览器response.addCookie(cookie);return redirect

14、:/toCart;Autowiredprivate SkuService skuService;/去购物车页面RequestMapping(value = /toCart)public String toCart(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception/1:从Request中取Cookies、遍历Cookie 取出之前购物车ObjectMapper om = new ObjectMapper();/不要NULL 不要转了om.setSerializationInc

15、lusion(Include.NON_NULL);/声明BuyerCart buyerCart = null;/1:从Request中取Cookies、Cookie cookies = request.getCookies();if(null != cookies& cookies.length 0)/遍历Cookie 取出之前购物车for (Cookie cookie :cookies) /2:判断Cookie中没有购物车if(Constants.BUYER_CART.equals(cookie.getName()/转回对象buyerCart = om.readValue(cookie.ge

16、tValue(),BuyerCart.class);break;if(null != buyerCart)/2:有 购物车数量及SKUID/把购物车装满List items = buyerCart.getItems();for (BuyerItem buyerItem :items) buyerItem.setSku(skuService.selectSkuById(buyerItem.getSku().getId();/3:没有/回显购物车内容model.addAttribute(buyerCart,buyerCart);/跳转到购物车页面return cart;6.3.2 优化之后裔码pa

17、ckage cn.itcast.core.controller;import java.io.StringWriter;import java.util.List;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stere

18、otype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import com.fasterxml.jackson.annotation.JsonInclude.Include;import com.fasterxml.jackson.databind.ObjectMapper;import mon.utils.RequestUtils;import mon.web.Constants;import cn.itcast.co

19、re.bean.BuyerCart;import cn.itcast.core.bean.BuyerItem;import cn.itcast.core.bean.product.Sku;import cn.itcast.core.service.product.SkuService;import cn.itcast.core.service.user.SessionProvider;/* * 购物车 * 去购物车页面 * 添加商品到购物车 * 删除 * + * author lx * */Controllerpublic class CartController Autowiredpriva

20、te SessionProvider sessionProvider;/加入购物车RequestMapping(value = /addCart)public String addCart(Long skuId,Integer amount,Model model,HttpServletRequest request,HttpServletResponse response) throws ExceptionObjectMapper om = new ObjectMapper();/不要NULL 不要转了om.setSerializationInclusion(Include.NON_NULL

21、);/声明BuyerCart buyerCart = null;/1:从Request中取Cookies、Cookie cookies = request.getCookies();if(null != cookies& cookies.length 0)/遍历Cookie 取出之前购物车for (Cookie cookie :cookies) /2:判断Cookie中没有购物车if(Constants.BUYER_CART.equals(cookie.getName()/转回对象buyerCart = om.readValue(cookie.getValue(),BuyerCart.clas

22、s);break;/3:有 /4:没有 创立购物车/判断购物车与否为nullif(null = buyerCart)buyerCart = new BuyerCart();/5:追加当前商品到购物车Sku sku = new Sku();/ID sku.setId(skuId);BuyerItem buyerItem = new BuyerItem();buyerItem.setSku(sku);/AmountbuyerItem.setAmount(amount);/追加商品到购物车buyerCart.addItem(buyerItem);/顾客与否登陆String username = se

23、ssionProvider.getAttributeForUsername(RequestUtils.getCSESSIONID(request,response);if(null != username)/3:有 把购物车中商品添加到Redis购物车中,skuService.insertBuyerCartToRedis(buyerCart,username);/清理之前Cookie4Cookie cookie = new Cookie(Constants.BUYER_CART,null);cookie.setMaxAge(0);cookie.setPath(/);response.addCo

24、okie(cookie);else/6:创立Cookie 把新购物车放进去StringWriter w = new StringWriter();om.writeValue(w,buyerCart);Cookie cookie = new Cookie(Constants.BUYER_CART,w.toString();/设立时间 写程序1天cookie.setMaxAge(60*60*24);/设立途径 cookie.setPath(/);/上线后 申请域名/7:保存写回浏览器response.addCookie(cookie);return redirect:/toCart;Autowir

25、edprivate SkuService skuService;/去购物车页面RequestMapping(value = /toCart)public String toCart(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception/1:从Request中取Cookies、遍历Cookie 取出之前购物车ObjectMapper om = new ObjectMapper();/不要NULL 不要转了om.setSerializationInclusion(Include.N

26、ON_NULL);/声明BuyerCart buyerCart = null;/1:从Request中取Cookies、Cookie cookies = request.getCookies();if(null != cookies& cookies.length 0)/遍历Cookie 取出之前购物车for (Cookie cookie :cookies) /2:判断Cookie中没有购物车if(Constants.BUYER_CART.equals(cookie.getName()/转回对象buyerCart = om.readValue(cookie.getValue(),BuyerCa

27、rt.class);break;if(null != buyerCart)/2:有 购物车数量及SKUID/把购物车装满List items = buyerCart.getItems();for (BuyerItem buyerItem :items) buyerItem.setSku(skuService.selectSkuById(buyerItem.getSku().getId();/3:没有/回显购物车内容model.addAttribute(buyerCart,buyerCart);/跳转到购物车页面return cart;7 问题7.1 同款商品合并非登陆登陆7.2 小计7.3 排序非登陆登陆7.4 去结算7.5 提交订单7.6 付款(不做了)

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服