@RequestMapping(value = "/profile", method = RequestMethod.GET) public String addressesPage(ModelMap model, HttpSession session) { try { UserInfo userInfo = getUserInfoBySpring(); List<Address> address = getPrimaryAddress(userInfo.getUserId()); // AddressForm addressForm = getAddressFormFromAddress(address); // model.addAttribute(AddressForm.class.getSimpleName(), addressForm); model.addAttribute("addresses", address); } catch (GcommerceException gcommerceException) { if (logger.isErrorEnabled()) { logger.error("addresses Exception", gcommerceException); } } return "profile"; }
@RequestMapping(value = "/update", method = RequestMethod.GET) public String addAddress(ModelMap model, HttpServletRequest request, @RequestParam(value = "id", required = false) Long id, HttpSession session) { try { if (id != null && id > 0) { Address address = userAccountService.findAddress(id); AddressForm addressForm = getAddressFormFromAddress(address); model.addAttribute("AddressForm", addressForm); } else { model.addAttribute(AddressForm.class.getSimpleName(), new AddressForm()); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("addAddress", e); } } return "updateAddress"; }
@RequestMapping(value = "/profile", method = RequestMethod.POST) public String addresses(ModelMap model, @Valid @ModelAttribute("AddressForm") AddressForm addressForm, BindingResult result, HttpSession session) { UserInfo userInfo = getUserInfoBySpring(); try { if (!result.hasErrors()) { if (addressForm.getId() == 0) { Address address = getAddressFromAddressForm(addressForm); if (address.isPrimary() == true) { List<Address> addressList = userAccountService.getUserAddresses(getUserInfoBySpring().getUserId()); for (int i = 0; i < addressList.size(); i++) { Address temp = addressList.get(i); temp.setPrimary(false); userAccountService.updateAddress(temp, userInfo.getUserId()); } } address = userAccountService.addAddress(address, userInfo.getUserId()); if (address != null) { addressForm.setId(address.getId()); } } else if (addressForm.getId() > 0 && addressForm.isDeleteOperation() == false) { Address address = getAddressFromAddressForm(addressForm); if (address.isPrimary() == true) { List<Address> addressList = userAccountService.getUserAddresses(getUserInfoBySpring().getUserId()); for (int i = 0; i < addressList.size(); i++) { Address temp = addressList.get(i); temp.setPrimary(false); temp = userAccountService.updateAddress(temp, userInfo.getUserId()); System.out.println(temp); } } address = userAccountService.updateAddress(address, userInfo.getUserId()); if (address != null) { addressForm.setId(address.getId()); } } else if (addressForm.getId() > 0 && addressForm.isDeleteOperation()) { userAccountService.removeAddress(addressForm.getId(), userInfo.getUserId()); model.addAttribute(AddressForm.class.getSimpleName(), new AddressForm()); } } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("addresses Exception", e); } } model.addAttribute("updated", true); return "updateAddress"; }
获取省市
@RequestMapping(value = "/getStatesAndCities.json", method = RequestMethod.GET) public @ResponseBody Map<String, String> getStatesAndCities(@RequestParam(value = "deliveryStateId", required = false) Integer deliveryStateId, @RequestParam(value = "deliveryCountryId", required = false) Integer deliveryCountryId, @RequestParam(value = "stateId", required = false) Integer stateId, @RequestParam(value = "countryId", required = false) Integer countryId, HttpServletRequest request, HttpSession session) throws Exception { Map<String, String> result = new TreeMap<String, String>(); Locale locale = getRequestLanguage(session, request); if (stateId != null && stateId > 0) { result = referenceDataService.getCitiesByStateId(-1, -1, "id", "desc", stateId, locale.toString()); return result; } if (deliveryStateId != null && deliveryStateId > 0) { result = referenceDataService.getCitiesByStateId(-1, -1, "id", "desc", deliveryStateId, locale.toString()); return result; } if (countryId != null && countryId > 0) { result = referenceDataService.getStatesByCountryId(-1, -1, "id", "desc", countryId, locale.toString()); return result; } if (deliveryCountryId != null && deliveryCountryId > 0) { result = referenceDataService.getStatesByCountryId(-1, -1, "id", "desc", deliveryCountryId, locale.toString()); return result; } return result; }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦