@RequestMapping("/register") public String registerCustomer(Model model) { Customer customer = new Customer(); BillingAddress billingAddress = new BillingAddress(); ShippingAddress shippingAddress = new ShippingAddress(); customer.setBillingAddress(billingAddress); customer.setShippingAddress(shippingAddress); model.addAttribute("customer", customer); return "registerCustomer"; }
@RequestMapping(value = "/register", method = RequestMethod.POST) public String registerCustomerPost( @Valid @ModelAttribute("customer") Customer customer, BindingResult result, Model model) { if (result.hasErrors()) { System.out.println("has errors"); return "registerCustomer"; } System.out.println("has errors postttt"); System.out.println("cutomer>>>" + customer); ArrayList customerList = new ArrayList(); customerList = customerService.getAllCustomers(); if (customerList != null && !customerList.isEmpty()) { for (int i = 0; i < customerList.size(); i++) { if (customer .getCustomerEmail() .equals((String) ((Customer) customerList.get(i)).getCustomerEmail())) { model.addAttribute("emailMsg", "Email already exists"); return "registerCustomer"; } if (customer .getUsername() .equals((String) ((Customer) customerList.get(i)).getUsername())) { model.addAttribute("usernameMsg", "Username already exists"); return "registerCustomer"; } } } customer.setEnabled(true); customerService.addCustomer(customer); return "registerCustomerSuccess"; }