版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、新巴巴運(yùn)動(dòng)網(wǎng) 項(xiàng)目第一天傳智.上官云課前回憶單點(diǎn)登陸 (搭建環(huán)境) 去登陸頁面( HYPERLINK http:/localhost:8082/login.aspx?return http:/localhost:8082/login.aspx?return Url = EncodeURLComment(window.location.href)提交登陸(1)顧客名、密碼、ReturnUrl)Value=login.aspx ,method=POST GET加密把顧客名保存Redis(Session共享) 1)分析K:V CSESSIONID:USER-Name V:fbb2)SessionPr
2、ovider ( SessionProviderImpl) 手動(dòng)實(shí)例化 (xml配備時(shí)間 60分鐘)3)保存顧客名到Redis中 7、 重定向到之前訪問頁面8、 頁面 (登陸、注冊、退出,我旳訂單) 分析:頁面(動(dòng)) 靜 ajax判斷顧客與否登陸頁面(前臺系統(tǒng)判斷顧客與否登陸) ajax 去此外一種系統(tǒng) 返回值被攔截(瀏覽器)判斷程序(單點(diǎn)登陸系統(tǒng))Ajax 返回值 :jsonjsonp登陸系統(tǒng)(接受String callback) Spring MappingJacksonValue (保存數(shù)據(jù) 返回JSONP旳數(shù)據(jù)) mjv.setJSONFunction(callback); retur
3、n mjv;(措施返回值處ResponseBody MappingJacksonValue今天內(nèi)容主打購物車購物車 面向?qū)ο笤O(shè)計(jì)購物車購物車 非登陸 登陸關(guān)閉瀏覽器還必須在跨電腦或區(qū)域購物車還在同款數(shù)量追加 同款商品合并排序同窗完畢面向?qū)ο笤O(shè)計(jì)購物車加入購物車設(shè)立途徑Controller分析購物車Cookie中Session中(Redis) 顧客名(顧客ID)數(shù)據(jù)庫非登陸:商品保存Cookie里 關(guān)閉瀏覽器還在 (七天、一種月)顧客清理Cookie就沒了登陸 : Redis 性能比較好 關(guān)閉瀏覽器(不登陸不在旳) 登陸就在了 (跨區(qū)域) 永久保存Redis保存購物車加入購物車加入購物車登陸非登
4、陸登陸非登陸1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車2:判斷Cookie中沒有購物車1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車2:判斷Cookie中沒有購物車3:有 把購物車中商品添加到Redis旳購物車中,清理之前Cookie4:沒有 5:直接添加目前商品到Redis中旳購物車?yán)?:從Request中取Cookies、遍歷Cookie 取出之前旳購物車2:判斷Cookie中沒有購物車3:有 4:沒有 創(chuàng)立購物車5:追加目前商品到購物車6:創(chuàng)立Cookie 把新購物車放進(jìn)去7:保存Cookie寫回瀏覽器去購物車頁面去購物車頁面判
5、斷與否登陸登陸1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車登陸1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車2:再把購物車保存到Redis中,清理Cookie3:從Redis中取出所有旳購物車把購物車裝滿跳轉(zhuǎn)到購物車頁面回顯購物車內(nèi)容1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車2:有 購物車數(shù)量及SKUID3:沒有把購物車裝滿跳轉(zhuǎn)到購物車頁面回顯購物車內(nèi)容購物車(回顯數(shù)據(jù)到購物車頁面購物車(回顯數(shù)據(jù)到購物車頁面 購物車對象與JSON字符串互轉(zhuǎn)SkuService入?yún)ⅲ?SKUID返回值:Sku對象SKu對象
6、(涉及顏色對象、商品對象)商品表SKU表顏色表保存商品到REdis中從Redis中取出購物車Controller未 優(yōu)化之前旳代碼package 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.
7、beans.factory.annotation.Autowired;import org.springframework.stereotype.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
8、mon.utils.RequestUtils;import mon.web.Constants;import cn.itcast.core.bean.BuyerCart;import cn.itcast.core.bean.BuyerItem;import duct.Sku;import duct.SkuService;import cn.itcast.core.service.user.SessionProvider;/* * 購物車 * 去購物車頁面 * 添加商品到購物車 * 刪除 * + * author lx * */Controllerpublic class CartControl
9、ler Autowiredprivate SessionProvider sessionProvider;/加入購物車RequestMapping(value = /addCart)public String addCart(Long skuId,Integer amount,Model model,HttpServletRequest request,HttpServletResponse response) throws ExceptionObjectMapper om = new ObjectMapper();/不要NULL 不要轉(zhuǎn)了om.setSerializationInclusio
10、n(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()/轉(zhuǎn)回對象buyerCart = om.readValue(cookie.getVa
11、lue(), BuyerCart.class);break;/顧客與否登陸String username = sessionProvider.getAttributeForUsername(RequestUtils.getCSESSIONID(request, response);if(null != username)if(null != buyerCart)/3:有 把購物車中商品添加到Redis旳購物車中,skuService.insertBuyerCartToRedis(buyerCart, username);/清理之前Cookie4Cookie cookie = new Cooki
12、e(Constants.BUYER_CART,null);cookie.setMaxAge(0);cookie.setPath(/);response.addCookie(cookie);/4:沒有 /5:直接添加目前商品到Redis中旳購物車?yán)?程序未寫else/3:有 /4:沒有 創(chuàng)立購物車/判斷購物車與否為nullif(null = buyerCart)buyerCart = new BuyerCart();/5:追加目前商品到購物車Sku sku = new Sku();/ID sku.setId(skuId);BuyerItem buyerItem = new BuyerItem()
13、;buyerItem.setSku(sku);/AmountbuyerItem.setAmount(amount);/追加商品到購物車buyerCart.addItem(buyerItem);/6:創(chuàng)立Cookie 把新購物車放進(jìn)去StringWriter w = new StringWriter();om.writeValue(w, buyerCart);Cookie cookie = new Cookie(Constants.BUYER_CART,w.toString();/設(shè)立時(shí)間 寫程序1天cookie.setMaxAge(60*60*24);/設(shè)立途徑 cookie.setPath(
14、/);/上線后 申請域名/7:保存寫回瀏覽器response.addCookie(cookie);return redirect:/toCart;Autowiredprivate SkuService skuService;/去購物車頁面RequestMapping(value = /toCart)public String toCart(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception/1:從Request中取Cookies、遍歷Cookie 取出之前旳購物車Object
15、Mapper om = new ObjectMapper();/不要NULL 不要轉(zhuǎn)了om.setSerializationInclusion(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_
16、CART.equals(cookie.getName()/轉(zhuǎn)回對象buyerCart = om.readValue(cookie.getValue(), BuyerCart.class);break;if(null != buyerCart)/2:有 購物車數(shù)量及SKUID/把購物車裝滿List items = buyerCart.getItems();for (BuyerItem buyerItem : items) buyerItem.setSku(skuService.selectSkuById(buyerItem.getSku().getId();/3:沒有/回顯購物車內(nèi)容model.
17、addAttribute(buyerCart, buyerCart);/跳轉(zhuǎn)到購物車頁面return cart;優(yōu)化之后旳代碼package 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.be
18、ans.factory.annotation.Autowired;import org.springframework.stereotype.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 mo
19、n.utils.RequestUtils;import mon.web.Constants;import cn.itcast.core.bean.BuyerCart;import cn.itcast.core.bean.BuyerItem;import duct.Sku;import duct.SkuService;import cn.itcast.core.service.user.SessionProvider;/* * 購物車 * 去購物車頁面 * 添加商品到購物車 * 刪除 * + * author lx * */Controllerpublic class CartControlle
20、r Autowiredprivate SessionProvider sessionProvider;/加入購物車RequestMapping(value = /addCart)public String addCart(Long skuId,Integer amount,Model model,HttpServletRequest request,HttpServletResponse response) throws ExceptionObjectMapper om = new ObjectMapper();/不要NULL 不要轉(zhuǎn)了om.setSerializationInclusion(
21、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()/轉(zhuǎn)回對象buyerCart = om.readValue(cookie.getValu
22、e(), BuyerCart.class);break;/3:有 /4:沒有 創(chuàng)立購物車/判斷購物車與否為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);/顧客與否登陸S
23、tring username = sessionProvider.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.set
24、Path(/);response.addCookie(cookie);else/6:創(chuàng)立Cookie 把新購物車放進(jìn)去StringWriter w = new StringWriter();om.writeValue(w, buyerCart);Cookie cookie = new Cookie(Constants.BUYER_CART,w.toString();/設(shè)立時(shí)間 寫程序1天cookie.setMaxAge(60*60*24);/設(shè)立途徑 cookie.setPath(/);/上線后 申請域名/7:保存寫回瀏覽器response.addCookie(cookie);return redirect:/toCart;Autowiredprivate SkuService skuService;/去購物車頁面RequestMapping(value = /toCart)public String toCart(Model mo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 認(rèn)識與實(shí)習(xí)報(bào)告范文集錦7篇
- 設(shè)計(jì)師實(shí)習(xí)報(bào)告(5篇)
- 2024年銅氧化物項(xiàng)目資金籌措計(jì)劃書代可行性研究報(bào)告
- 2024年海洋環(huán)保儀器及采樣設(shè)備項(xiàng)目投資申請報(bào)告代可行性研究報(bào)告
- 2023年娛樂、游覽用船舶資金需求報(bào)告
- 高考考場作文的類型 教案-高考作文寫作提升課堂
- 湖北名師聯(lián)盟2025年高三下期末考試化學(xué)試題含解析
- 黑龍江省綏化市2024-2025學(xué)年高三第一次聯(lián)考(5月)化學(xué)試題試卷含解析
- 川教版(2019)七年級下冊 信息技術(shù) 2.4 匯報(bào)成果 展示評價(jià) 教案
- 九下名著第六單元外國小說的閱讀《簡愛》整本書閱讀教學(xué)設(shè)計(jì)
- 兒童核磁檢查護(hù)理
- 勞動(dòng)關(guān)系協(xié)調(diào)員四級理論考試備考題庫(重點(diǎn)600題)
- 2024秋國家開放大學(xué)《馬克思主義基本原理》專題測試1-8參考答案
- 2023年十堰鄖西縣事業(yè)單位招聘筆試真題
- 2024-2025學(xué)年統(tǒng)編版道德與法治一年級上冊教學(xué)設(shè)計(jì)(附目錄)
- 水利安全生產(chǎn)風(fēng)險(xiǎn)防控“六項(xiàng)機(jī)制”右江模式經(jīng)驗(yàn)分享
- DLT 5630-2021 輸變電工程防災(zāi)減災(zāi)設(shè)計(jì)規(guī)程-PDF解密
- 【川教版】《生命 生態(tài) 安全》二年級上冊第3課 我的雞蛋寶寶 課件
- 三年級語文上冊第五單元【教材解讀】
- 授居家二眾三皈、五戒儀規(guī)
- 應(yīng)急救援流程圖
評論
0/150
提交評論