在cartcontroller.java中aclipyconfim还会用到lisbean.java
在cart-2页面利用隐藏方式传入,用循环
div class="col-md-10 ceterR"> <ul class="progressBar cf mt15"> <li class="curr"><i class="yh">1</i>我的购物车</li> <li class="curr"><i class="yh">2</i>填写收货地址并支付</li> <li><i class="yh">3</i>下单成功</li></ul> 利用form表单action="alipaySubmit"方法提交到alipy支付宝页面,cart-2是用来显示用户的收货地址,利用隐式方式传入 <form name="alipayForm" action="alipaySubmit" th:object="${alipayForm}" method="post" class="form-horizontal form-address mt20"> <input type="hidden" name="outTradeNo" value="" th:value="${alipayForm.outTradeNo}"/> <input type="hidden" name="subject" value="" th:value="${alipayForm.subject}"/> <input type="hidden" name="body" value="" th:value="${alipayForm.body}"/> <input type="hidden" name="price" value="" th:value="${alipayForm.price}"/> <input type="hidden" name="showUrl" value="" th:value="${alipayForm.showUrl}"/> <input type="hidden" name="receiveName" value="" th:value="${alipayForm.receiveName}"/> <input type="hidden" name="receiveAddress" value="" th:value="${alipayForm.receiveAddress}"/> <input type="hidden" name="receiveZip" value="" th:value="${alipayForm.receiveZip}"/> <input type="hidden" name="receivePhone" value="" th:value="${alipayForm.receivePhone}"/> <input type="hidden" name="receiveMobile" th:value="${alipayForm.receiveMobile}"/> <ul> 利用li来做一个循环通过th:each <li th:each="cartForm,status:${alipayForm.cartFormList}"> <input type="hidden" th:name="${#strings.concat('cartFormList[').concat(status.index).concat('].cartId')}" th:value="${cartForm.cartId}"/></li></ul> <div class="table-responsive mt20"> <table class="table table-order table-cart table-address"> <thead><tr> <th class="wp15"><p class="tl ml20">姓名</p></th> <th class="wp40">收货地址</th> <th class="wp10">邮编</th> <th class="wp15">电话号码</th> <th class="wp20">操作</th></tr></thead> <tbody> <tr th:each="receiveInfo,status:${list}"> 用th:each作循环 <td class="chk"><input type="radio" name="point" class="vm"/> <span th:text="${receiveInfo.receiveName}"></span></td> <td><span th:text="${receiveInfo.addressName}"></span></td> <td><span th:text="${receiveInfo.post}"></span></td> <td><span th:text="${receiveInfo.phone}"></span></td><td> <a th:href="@{defaultAddress(addressId=${receiveInfo.addressId})}" class="link mr10" th:if="${receiveInfo.addressId}!=${addressDefault}">设为默认地址</a> <a th:href="@{initEditReceive(addressId=${receiveInfo.addressId})}" class="link mr10">修改</a> <a th:href="@{deleteReceive(addressId=${receiveInfo.addressId})}" class="link">删除</a> </td> </tr></tbody> </table></div> <p class="yellow f14 mt30">支付方式</p> <p class="payWay mt10"><input type="checkbox" class="vm"/> 支付宝支付</p> <p class="tr mt20"><button class="btnBlue yh">去支付</button></p></form>
在alipay.controller
利用这个返回到alipy调到支付宝页面。通过支付宝支付成功返回到cart-3 @RequestMapping(value = "alipaySubmit", method = RequestMethod.POST) public String executeAlipaySubmit(Model model, HttpSession session, @Valid @ModelAttribute("alipayForm") AlipayForm alipayForm, BindingResult results, Device device) throws SQLException { GoodsForm goodsForm=new GoodsForm(); // goodsForm.setType("粮食"); // model.addAttribute("goodsForm", goodsForm); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); log.info("修改购物车信息为已付款"); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) { return "redirect:/initGuestLogin"; } alipayForm.setUpdateUser(uvo.getGuestName()); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); alipayForm.setUpdateTime(dateformat.format(date)); alipayForm.setGuestId(uvo.getGuestId()); boolean hisResult = cartService.addAlipayHistory(alipayForm); if(!hisResult) { throw new SQLException("添加支付宝账单失败!"); } CartForm cartForm = new CartForm(); cartForm.setUpdateUser(uvo.getGuestName()); cartForm.setUpdateTime(dateformat.format(date)); cartForm.setGuestId(uvo.getGuestId()); int b = alipayForm.getCartFormList().size(); for (int k = 0; k < b;k++) { cartForm.setCartId(alipayForm.getCartFormList().get(k).getCartId()); boolean result = cartService.editStatus(cartForm); if(!result) { throw new SQLException("修改支付状态失败!"); } } if(device.isNormal()) { model.addAttribute("sHtmlText", alipayRequestWeb(alipayForm)); } else { model.addAttribute("sHtmlText", alipayRequestMobile(alipayForm)); } return "manager/charge/alipay"; }
修改/设默认地址/删除在ReceiveController.java
@RequestMapping(value = "deleteReceive", method = RequestMethod.GET) public String executeDeleteReceive(Model model, HttpSession session, @Valid @ModelAttribute("receiveForm") ReceiveForm receiveForm, BindingResult results, Device device) throws SQLException { GuestForm guestForm = new GuestForm(); UVO uvo=(UVO) session.getAttribute("UVO"); guestForm.setGuestId(uvo.getGuestId()); String addressDefault=guestService.searchAddressId(guestForm).getAddressId(); model.addAttribute("addressDefault", addressDefault); receiveForm.setGuestId(uvo.getGuestId()); GoodsForm goodsForm = new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); // GuestForm guestForm=new GuestForm(); // guestForm.setGuestId(receiveForm.getGuestId()); // String addressDefault=guestService.searchAddress(guestForm).getAddress(); if(receiveForm.getAddressId().equals(addressDefault)){ guestForm.setAddressId(""); boolean result=guestService.editGuestAddressId(guestForm); if(result) {receiveservice.deleteAddress(receiveForm); } List<ReceiveForm> list= receiveservice.searchlist(receiveForm); model.addAttribute("list",list); ReceiveForm receiveForm1=new ReceiveForm(); receiveForm1.setGuestId(uvo.getGuestId()); receiveForm1.setAddressId(""); model.addAttribute("receiveForm", receiveForm1); if(device.isNormal()) { return "shop/address"; } else { return "mobile/address"; } } else{ int result= receiveservice.deleteAddress(receiveForm); if(result==1) {List<ReceiveForm> list= receiveservice.searchlist(receiveForm); model.addAttribute("list",list); ReceiveForm receiveForm1=new ReceiveForm(); receiveForm1.setGuestId(uvo.getGuestId()); receiveForm1.setAddressId(""); model.addAttribute("receiveForm", receiveForm1); } if(device.isNormal()) { return "shop/address"; } else { return "mobile/address"; } } } @RequestMapping(value = "defaultAddress", method = RequestMethod.GET) public String setDefault(Model model, HttpSession session, @Valid @ModelAttribute("receiveForm") ReceiveForm receiveForm, BindingResult results, Device device) throws SQLException { UVO uvo = (UVO)session.getAttribute("UVO"); receiveForm.setGuestId(uvo.getGuestId()); GoodsForm goodsForm = new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); CartForm cartForm = new CartForm(); cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("receiveForm", receiveForm); GuestForm guestForm = new GuestForm(); guestForm.setGuestId(uvo.getGuestId()); String addressDefault=guestService.searchAddressId(guestForm).getAddressId(); guestForm.setAddressId(receiveForm.getAddressId()); boolean result=guestService.editGuestAddressId(guestForm); if(result){ addressDefault=guestForm.getAddressId(); model.addAttribute("addressDefault",addressDefault); receiveForm.setAddressId(""); } else { throw new SQLException("默认地址设置失败!"); } List<ReceiveForm> list= receiveservice.searchlist(receiveForm); model.addAttribute("list",list); if(device.isNormal()) { return "shop/address"; } else { return "mobile/address"; } } @RequestMapping(value = "initEditReceive", method = RequestMethod.GET) public String initEditReceive(Model model, HttpSession session, @Valid @ModelAttribute("receiveForm") ReceiveForm receiveForm, Device device) { log.info("修改收货人信息初始化"); GuestForm guestForm = new GuestForm(); UVO uvo=(UVO) session.getAttribute("UVO"); guestForm.setGuestId(uvo.getGuestId()); String addressDefault=guestService.searchAddressId(guestForm).getAddressId(); model.addAttribute("addressDefault", addressDefault); GoodsForm goodsForm = new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); receiveForm=receiveservice.searchReceive(receiveForm); model.addAttribute("receiveForm", receiveForm); List<ReceiveForm> list=receiveservice.searchlist(receiveForm); model.addAttribute("list", list); if(device.isNormal()) { return "shop/address"; } else { return "mobile/address";