將guestAlipay.jsp頁面改寫成guestAlipay.html頁面html
本頁面的主要功能:實現匿名購買,填寫訂單信息後可點擊按鈕登陸支付寶結帳java
1.將JSP頁面中的全部JSP標籤所有替換成HTML中能夠識別的標識。session
2.還須要調用的頁面爲:AlipayController.java和CartController.java。app
3.完成頁面標籤的修改以後,調試出現的錯誤信息。jsp
(1)goodsForm.type="糧食"的錯誤信息。post
調試解決:在AlipayController.java和CartController.java中須要對糧食進行實例化,附初值spa
(2)cartList==0的錯誤信息。調試
調試解決:匿名購買時沒有購物車,可是寫成HTML時要求比較嚴格,因此必須添加購物車,因此在AlipayController.java中對購物車進行實例化。code
1.guestAlipay.jsp中orm
<ul class="user_menu"> <jsp:include page="/WEB-INF/jsp/shop/userBar.jsp"></jsp:include> </ul>
guestAlipay.html改寫爲:
<ul> <div th:replace="shop/userBar :: page-user-bar"></div> </ul>
2.guestAlipay.jsp中
<form:form modelAttribute="alipayForm" action="guestAlipaySubmit" method="post"> <form:hidden path="outTradeNo" value="${alipayForm.outTradeNo}"/> <form:hidden path="subject" value="${alipayForm.subject}"/> <form:hidden path="body" value="${alipayForm.body}"/> <form:hidden path="price" value="${alipayForm.price}"/> <form:hidden path="showUrl" value="${alipayForm.showUrl}"/> <form:hidden path="commodityId" value="${alipayForm.commodityId}"/> <form:hidden path="guestId" value="${alipayForm.guestId}"/> <form:hidden path="count" value="${alipayForm.count}"/> </form:form>
guestAlipay.html改寫爲:
<form action="guestAlipaySubmit" th:object="${alipayForm}" method="post"> <input name="outTradeNo" type="hidden" th:value="${alipayForm.outTradeNo}" /> <input name="subject" type="hidden" th:value="${alipayForm.subject}" /> <input name="body" type="hidden" th:value="${alipayForm.body}" /> <input name="price" type="hidden" th:value="${alipayForm.price}" /> <input name="showUrl" type="hidden" th:value="${alipayForm.showUrl}" /> <input name="commodityId" type="hidden" th:value="${alipayForm.commodityId}" /> <input name="guestId" type="hidden" th:value="${alipayForm.guestId}" /> <input name="count" type="hidden" th:value="${alipayForm.count}" /> </form>
3.guestAlipay.jsp中
<h1> 您如今是匿名購買該商品,請認真填寫如下每項內容以保證商品可以順利到達您的手中。<br/> ${message}<form:errors path="*"></form:errors> </h1>
guestAlipay.html改寫爲:
<h1> 您如今是匿名購買該商品,請認真填寫如下每項內容以保證商品可以順利到達您的手中。 <span th:errors="${alipayForm.*}"></span> <span th:text="${message}"></span> </h1>
4.CartController.java
@RequestMapping(value = "addCart", method = RequestMethod.POST) public String executeAddCart(Model model, HttpSession session, CartForm cartForm, Device device) throws SQLException { GoodsForm GoodsForm=new GoodsForm(); GoodsForm.setType("糧食"); model.addAttribute("goodsForm", GoodsForm); model.addAttribute("cartList", cartService.searchCartList(cartForm)); log.info("追加購物車");
5.AlipayController.java
@RequestMapping(value = "guestAlipaySubmit", method = RequestMethod.POST) public String executeGuestAlipaySubmit(Device device, Model model, @Valid @ModelAttribute("alipayForm") AlipayForm alipayForm, BindingResult results) throws SQLException { GoodsForm goodsForm=new GoodsForm(); goodsForm.setType("糧食"); model.addAttribute("goodsForm", goodsForm); log.info("由匿名用戶購買商品向支付寶發起支付請求。");