コード例 #1
0
  @RequestMapping("/add")
  @ResponseBody
  public CustomerAddress addAddress(
      @RequestParam String name,
      @RequestParam String address,
      @RequestParam String city,
      @RequestParam int countryCode,
      @RequestParam String postCode,
      HttpSession session) {
    Customer customer = (Customer) session.getAttribute("customer");
    int customerId = customer.getId();
    Country country = countryMapper.getCountryById(countryCode);

    CustomerAddress customerAddress =
        new CustomerAddress(
            name, address, city, country.getName(), countryCode, postCode, customerId);

    customerAddressMapper.insertCustomerAddress(customerAddress);
    return customerAddress;
  }
コード例 #2
0
  @RequestMapping("/{id}/update")
  @ResponseBody
  public String updateAddress(
      @PathVariable int id,
      @RequestParam String name,
      @RequestParam String address,
      @RequestParam String city,
      @RequestParam int countryCode,
      @RequestParam String postCode,
      HttpSession session) {
    CustomerAddress customerAddress = customerAddressMapper.getCustomerAddressById(id);
    Country country = countryMapper.getCountryById(countryCode);

    customerAddress.setAddress(address);
    customerAddress.setCity(city);
    customerAddress.setCountry(country.getName());
    customerAddress.setCountryCode(countryCode);
    customerAddress.setName(name);
    customerAddress.setPostCode(postCode);
    customerAddressMapper.insertCustomerAddress(customerAddress);
    return "success";
  }