版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、新巴巴運動網(wǎng)總結(jié)筆記 day07項目第七天(課程安排)1.1購物車要求關(guān)閉瀏覽器,再打開時還要有商品,并且不登陸也要有商品購物車對象的創(chuàng)建,購物子項對象的創(chuàng)建購物車中屬于最小單元的同類商品,商品數(shù)量增加,不同類商品加入購物車結(jié)算1)2)3)判斷此時此刻是否有庫存判斷是否為登陸狀態(tài)判斷購物車中是否有商品1按鈕跳轉(zhuǎn)到購物車第一步:要求加入購物車的在沒有登陸的時候起來或Ses可采用最后或數(shù)據(jù)庫進(jìn)行進(jìn)行采用第二步:編寫 front_page/product/productDetail.jsp按鈕/立即參數(shù)商品ID第三步:創(chuàng)建 FrontCartController 類并編寫方法第 步
2、:編寫進(jìn)行數(shù)據(jù)測試準(zhǔn)備/* 購物車在*/中的名稱public sic final String BUYCART_= buyCart_;實例化-1 關(guān)閉瀏覽器消毀0 立即消毀/實例化,并指定= new的名稱(Constants.BUYCART_,str.toString();/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1四/*購物車author lx*/ Controllerpublic class FrontCartController /RequestMap(value = /shop/buyCart.shtml)public String buyCart(eger skuId,eg
3、er amount,eger buyLimit,egroductId,HttpServletResponse response,HttpServletRequest request, MMap m)function buy(id)window.location.href = /shop/buyCart.shtml?skuId= + skuId + &amount= + $(#num).val() + &buyLimit= + buyLimit + &productId=+ id;-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/將發(fā)送到瀏覽器resp
4、onse.add();第五步:跳轉(zhuǎn)購物車頁面第六步:創(chuàng)建購物車對象位置購物項對象 BuyItem購物車對象 BuyCart/*購物車author lx*/public class BuyCart /*購物的商品,項author lx*/public class BuyItem /最小銷售單元 private Sku sku ;/買多少件 數(shù)量privateamount = 1;/省略set get 添加購物項刪除購物項/刪除購物項public void removeItem(BuyItem item) if(items.contains(item)items.remove(item);/添加購
5、物項public void addItem(BuyItem item) if(items.contains(item)for(BuyItem it : items) if(it.equals(item)amount = item.getAmount() + it.getAmount(); if(amount = it.getSku().getSkuUpperLimit()it.setAmount(it.getSku().getSkuUpperLimit() -1);elseit.setAmount(item.getAmount() +it.getAmount();break;elseitems
6、.add(item);/有多個購物項privaist items = new ArrayList();/留言private String note;/最后一次加入購物車時的商品Id privateegroductId;/省略 set get 消空購物車商品數(shù)量商品金額商品運費/商品運費 JsonIgnorepublic Double getFee() Double result = 0.00;if(getProductPrice() 0) result = true;return result;/應(yīng)付金額 JsonIgnorepublic Double getTotalPrice() Doub
7、le result = 0.00;result += getProductPrice() + getFee(); return result;第八步:從象中取出 Value 并反序列化為購物車對/購物車對象BuyCart buyCart = null;/把對象在中需要將對象序列化成字符串ObjectMapper om = new ObjectMapper();/序列化的字符串中不要有Null om.setSerializationInclu(Inclu.NON_NULL);s = request.gets(); if(null !=s)for(:s)if(Constants.BUYCART_.
8、equals(.getName()String value =.getValue();/System.out.prln(value);buyCart = om.readValue(value, BuyCart.class);/用戶對象Buyer b = new Buyer(); b.setUsername(fbb2014);/對象序列化字符串/ObjectMapper om = new ObjectMapper(); om.setSerializationInclu(Inclu.NON_NULL);StringWriter str = new StringWriter();/om.writeV
9、alue(str, b); System.out.prln(str.toString();/反序列化過程/字符串轉(zhuǎn)成對象Buyer readValue = om.readValue(str.toString(), Buyer.class);System.out.prln(readValue.toString();第九步:如果是第一步加入購物車,沒有第十步:將購物車序列化成 JSON 并在中if(null != skuId)/實例化SKUSku sku = new Sku();/將SkuID設(shè)置給Sku對象 sku.setId(skuId);/設(shè)置限購 sku.setSkuUpperLimit(
10、buyLimit);/實例化購物車BuyItem item = new BuyItem();/將Sku對象設(shè)置給購物項 item.setSku(sku);/將商品數(shù)量設(shè)置給購物項 item.setAmount(amount);/將商品Id加入購物車 buyCart.setProductId(productId);/添加購物購物車buyCart.addItem(item); /同類產(chǎn)品需要比較如果SkuId一樣視為相同產(chǎn)品/實例化一個字符串的流,序列化后的字符串StringWriter str = new StringWriter();/開始序列化 om.writeValue(str, buyC
11、art);/實例化,并指定的名稱= new (Constants.BUYCART_,str.toString();/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/實例化購物車只為第一次購物if(null = buyCart) buyCart = new BuyCart();第十一步:把購物車裝滿,顯示在購物車頁面上第十二步:購物車頁面 front_page/product/cart.jsp顯示商品部分的代碼$ -$item. -$item.sku.size 【贈品】絲帶/將購物車?yán)锏臄?shù)據(jù)裝滿,為
12、了在購物車頁面顯示的數(shù)據(jù)全都有/加載SkuId對應(yīng)的屬性List items = buyCart.getItems(); for(BuyItem it : items)Sku skuByKey = skuService.getSkuByKey(it.getSku().getId(); it.setSku(skuByKey);/將購物車m到購物車頁面上去m.addAttribute(buyCart, buyCart);/將最后添加的商品ID 傳回頁面m.addAttribute(productId, buyCart.getProductId();return product/cart;/將發(fā)送到
13、瀏覽器response.add();購物車統(tǒng)計處代碼第十三步:刪除購物車金額小計:(共$buyCductAmount 個商品)商品金額:¥$buyCductPrice 元運費:¥$buyCart.fee 元應(yīng)付總額:¥$buyCart.totalPrice 元¥$item.sku.skuPrice-+刪除頁面Js:刪除購物項之后刷新頁面重新加載購物中的數(shù)據(jù)/刪除購物車中的購物項RequestMap(value = /shop/delItem.shtml) public String delItem(eger skuId,HttpServletRequestrequest,HttpServlet
14、Response response) throws JsonParseException, JsonMapException, IOException/購物車對象BuyCart buyCart = null;/把對象在中需要將對象序列化成字符串ObjectMapper om = new ObjectMapper();/序列化的字符串中不要有Null om.setSerializationInclu(Inclu.NON_NULL);s = request.gets(); if(null !=s)for(:s)if(Constants.BUYCART_.equals(.getName()Strin
15、g value =.getValue();/System.out.prln(value);buyCart = om.readValue(value, BuyCart.class);/實例化購物車只為第一次購物if(null != buyCart)Sku sku = new Sku();/刪除商品function delProduct(skuId) if(confirm(你確定要刪除此商品嗎?)window.location.href = /shop/delItem.shtml?skuId= +skuId;刪除第十三步:+ - 按鈕頁面Js+/添加商品數(shù)量 (skuid , 限購)functio
16、n addProductAmount(skuId,upperLimit) var num = $(#num + skuId).val();/alert(num);num+;-+sku.setId(skuId);BuyItem item = new BuyItem(); item.setSku(sku); buyCart.removeItem(item);/實例化一個字符串的流,序列化后的字符串StringWriter str = new StringWriter();/開始序列化 om.writeValue(str, buyCart);/實例化,并指定的名稱= new (Constants.B
17、UYCART_,str.toString();/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/將發(fā)送到瀏覽器response.add();return redirect:/shop/buyCart.shtml;Js-/添加購物車中的商品數(shù)量/減少商品數(shù)量function subProductAmount(skuId,upperLimit) var num = $(#num + skuId).val();num-; if(num = 0)delProduct(skuId); return;$(#n
18、um + skuId).val(num);/更改購物車中的數(shù)據(jù) 更改中的數(shù)量var url = /shop/addCart.shtml;var params = skuId : skuId,buyLimit : upperLimit,amount : -1;$.t(url,params,function(data)$(#productAmount).html(ductAmount);$(#productPrice).html(ductPrice);$(#fee).html(data.fee);$(#totalPrice).html(daotalPrice);,json);if(num = up
19、perLimit)alert(此款商品不允許買 + upperLimit + 件); return ;$(#num + skuId).val(num);/更改購物車中的數(shù)據(jù) 更改中的數(shù)量var url = /shop/addCart.shtml;var params = skuId : skuId,buyLimit : upperLimit,amount : 1;$.t(url,params,function(data)$(#productAmount).html(ductAmount);$(#productPrice).html(ductPrice);$(#fee).html(data.fe
20、e);$(#totalPrice).html(daotalPrice);,json);RequestMap(value = /shop/addCart.shtml)public void addCart(eger skuId,eger amount,egerbuyLimit,HttpServletRequest request,HttpServletResponse response)throwsJsonParseException, JsonMap/實例化SkuSku sku = new Sku();sku.setId(skuId);Exception, IOExceptionsku.set
21、SkuUpperLimit(buyLimit);/實例化購物項BuyItem item = new BuyItem(); item.setSku(sku);item.setAmount(amount);/獲取/購物車對象中的購物車BuyCart buyCart=null;中需要將對象序列化成字符串new ObjectMapper();/把對象在ObjectMapper om=/序列化的字符串中不要有Null om.setSerializationInclu(Inclu.NON_NULL);if(null != for(s= request.gets)s();:s)if(Constants.BU
22、YCART_String.equals(value =.getName().getValue(); ln(value);/System.out.prbuyCart = om.readValue(value,BuyCart.class);/實例化購物車只為第一次購物if(null = buyCart)buyCart = new BuyCart();/添加購物購物車buyCart.addItem(item); /同類產(chǎn)品需要比較如果SkuId一樣 視為相同產(chǎn)品/實例化一個字符串的流,序列化后的字符串StringWriter str = new StringWriter();/開始序列化 om.wr
23、iteValue(str, buyCart);/實例化,并指定= new的名稱(Constants.BUYCART_,str.toString();第十步:消空購物車頁面Js/消空購物車四/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/將發(fā)送到瀏覽器response.add();/將購物車?yán)锏臄?shù)據(jù)裝滿,為了在購物車頁面顯示的數(shù)據(jù)全都有/加載SkuId對應(yīng)的屬性List items = buyCart.getItems(); for(BuyItem it : items)Sku skuByKey
24、= skuService.getSkuByKey(it.getSku().getId(); it.setSku(skuByKey);DecimalFormat df = new DecimalFormat(.00);/回調(diào)數(shù)據(jù)JSONObject jo = new JSONObject();/商品數(shù)量jo.put(productAmount, buyCart.getProductAmount();/商品金額jo.put(productPrice, df.format(buyCart.getProductPrice();/商品運費jo.put(fee, df.format(buyCart.get
25、Fee();/商品應(yīng)付金額jo.put(totalPrice, df.format(buyCart.getTotalPrice();ResponseUtils.renderJson(response, jo.toString();RequestMap(value = /shop/clearCart.shtml)JsonMapException, IOException/設(shè)置時間,讓瀏覽器器上的對應(yīng)的馬上失效 設(shè)置0馬上失效/.setMaxAge(0);/response.add();/把對象在中需要將對象序列化成字符串om.setSerializationInclu(Inclu.NON_NUL
26、L); s = request.gets();if(null != s) if(Constants.BUYCART_.equals(.getName()String value = .getValue();/System.out.prln(value);/實例化一個字符串的流,序列化后的字符串/實例化,并指定的名稱 = new(Constants.BUYCART_,str.toString();StringWriter str = new StringWriter();/開始序列化 om.writeValue(str, buyCart);buyCart = om.readValue(value
27、, BuyCart.class);/實例化購物車只為第一次購物if(null != buyCart) buyCart.clearItem();for( : s)ObjectMapper om = new ObjectMapper();/序列化的字符串中不要有Null/購物車對象BuyCart buyCart = null;/ = new (Constants.BUYCART_,null); public String clearCart(HttpServletRequest request, HttpServletResponse response) throws JsonParseExcep
28、tion,/消空購物車function clearCart()window.location.href = /shop/clearCart.shtml;消空后頁面顯示部分不消空時顯示的部分第十五步:繼續(xù)購物去首頁挑選喜歡的商品/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/將發(fā)送到瀏覽器response.add();return redirect:/shop/buyCart.shtml;2加入購物車按鈕按鈕中第十三步相同,在這里不寫了此按鈕與3結(jié)算按鈕頁面Js判斷用戶是否登陸-此功能已經(jīng)在用戶登
29、陸處已經(jīng)完成了,可復(fù)用-結(jié)算請求路徑需要以/buyer/開始/結(jié)算RequestMap(value = /buyroductOrder.shtml)public String productOrder(HttpServletRequest request,MMap m,HttpServletResponse response) throws JsonParseException, JsonMapException, IOException/判斷登陸 由buyer完成了/判斷購物車中是否有東西/判斷購物車中的東西是否還有庫存/購物車對象BuyCart buyCart = null;/把對象在中需
30、要將對象序列化成字符串ObjectMapper om = new ObjectMapper();/結(jié)算function trueBuy()window.location.href = /buyroductOrder.shtml;判斷購物車是否存在商品,如果有商品是否還有庫存/實例化購物車只為第一次購物if(null != buyCart)/判斷購物車是否有商品 if(buyCart.isExitItem()/判斷商品是否還有庫存for(BuyItem item : buyCart.getItems()Sku sku = skuService.getSkuByKey(item.getSku().
31、getId();if(sku.getStockInventory() = 0) buyCart.removeItem(item);/實例化一個字符串的流,序列化后的字符串StringWriter str = new StringWriter();/開始序列化 om.writeValue(str, buyCart);/實例化,并指定的名稱= new (Constants.BUYCART_,str.toString();/1)給設(shè)置時間,如果不設(shè)置時間,默認(rèn)下 時間為 -1-1表示關(guān)閉瀏覽器會自動掉.setMaxAge(60*60*24);.setPath(/);/將發(fā)送到瀏覽器response.add();else/序列化的字符串中不要有Null om.setSerializationInclu(Inclu.NON_NULL);s = request.gets(); if(null !=s)for(:s)if(Constants.BUYCART_.equals(.getName()String value =.getValue();/System.out.prln(value);buyCart =
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 幼兒花木蘭古詩
- 春天在哪里幼兒園語言活動教案集錦五篇
- 采購價格與成本管理
- 濾芯相關(guān)行業(yè)投資規(guī)劃報告
- 如何人工模擬神經(jīng)元
- 《 察哈素3號煤層采空區(qū)自燃機(jī)理及“三帶”監(jiān)測研究》
- 《 復(fù)雜電磁環(huán)境中輻射近場預(yù)測算法研究》范文
- 《 性侵未成年人犯罪疑難問題研究》范文
- 《2024年“可能世界”與影視劇本體觀念的拓展-從國產(chǎn)時空循環(huán)劇出發(fā)》范文
- 《 C計量公司人力資源規(guī)劃研究》范文
- 民以食為天糧以儉為先 (修訂)
- 中小學(xué)文體活動方案
- 生物-2024屆湖北騰云聯(lián)盟上學(xué)期高三年級十月聯(lián)考試題和答案
- 2024年4月自考00316西方政治制度試題及答案含評分標(biāo)準(zhǔn)
- 《電腦效果圖后期處理》課件-效果圖后期新中式酒店案例
- 教育部2024年專項任務(wù)項目(高校輔導(dǎo)員研究)申請評審書《新時代創(chuàng)新落實立德樹人根本任務(wù)的路徑和方法研究》
- 京東單品推廣方案
- 《饅頭制作過程》課件
- 高考真題化學(xué)平衡專題
- 新生兒健康評估中的喂養(yǎng)指導(dǎo)
- 淺談自閉癥兒童的感覺統(tǒng)合訓(xùn)練
評論
0/150
提交評論