예제 #1
0
 // 收货地址保存
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 public String save(ModelMap map, HttpServletRequest request, Receiver receiver) {
   if (StringUtils.isEmpty(receiver.getPhone()) && StringUtils.isEmpty(receiver.getMobile())) {
     map.put("errorMessage", "联系电话、联系手机必须填写其中一项!");
     return ERROR;
   }
   if (!areaService.isAreaPath(receiver.getAreaPath())) {
     map.put("errorMessage", "地区错误!");
     return ERROR;
   }
   Area localArea =
       (Area)
           areaService.get(
               receiver.getAreaPath().substring(receiver.getAreaPath().lastIndexOf(",") + 1));
   if (localArea == null) {
     map.put("errorMessage", "请选择收货地址!");
     return ERROR;
   }
   receiver.setArea(localArea);
   Members loginMember = getLoginMember(request);
   Set<Receiver> receiverSet = loginMember.getReceiverSet();
   if (receiverSet != null
       && Receiver.MAX_RECEIVER_COUNT != null
       && receiverSet.size() >= Receiver.MAX_RECEIVER_COUNT) {
     map.put("errorMessage", "只允许添加最多" + Receiver.MAX_RECEIVER_COUNT + "项收货地址!");
     return ERROR;
   }
   receiver.setMember(loginMember);
   receiverService.save(receiver);
   map.put("redirectUrl", OPERRATE_RETURN_URL);
   return SUCCESS;
 }
예제 #2
0
 // 收货地址更新
 @RequestMapping(value = "/update", method = RequestMethod.POST)
 public String update(
     ModelMap map, HttpServletRequest request, Receiver receiver, @RequestParam("id") String id) {
   if (StringUtils.isEmpty(receiver.getMobile()) && StringUtils.isEmpty(receiver.getPhone())) {
     map.put("errorMessage", "联系手机、联系电话必须填写其中一项!");
     return ERROR;
   }
   if (!areaService.isAreaPath(receiver.getAreaPath())) {
     map.put("errorMessage", "地区错误!");
     return ERROR;
   }
   Receiver persistent = receiverService.load(id);
   if (persistent.getMember() != getLoginMember(request)) {
     map.put("errorMessage", "参数错误!");
     return ERROR;
   }
   BeanUtils.copyProperties(
       receiver, persistent, new String[] {"id", "createDate", "modifyDate", "member"});
   receiverService.update(persistent);
   map.put("redirectUrl", OPERRATE_RETURN_URL);
   return SUCCESS;
 }