@PostMapping("/owners/new") public String processCreationForm(@Valid Owner owner, BindingResult result) { if (result.hasErrors()) { return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; } else { this.owners.save(owner); return "redirect:/owners/" + owner.getId(); } }
@GetMapping("/owners") public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search } // find owners by last name Collection<Owner> results = this.owners.findByLastName(owner.getLastName()); if (results.isEmpty()) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } else { // multiple owners found model.put("selections", results); return "owners/ownersList"; } }
@Override public String toString() { return new ToStringCreator(this) .append("id", this.getId()).append("new", this.isNew()) .append("lastName", this.getLastName()) .append("firstName", this.getFirstName()).append("address", this.address) .append("city", this.city).append("telephone", this.telephone).toString(); } }
@RequestMapping(value = "/owners/new", method = RequestMethod.POST) public String processCreationForm(@Valid Owner owner, BindingResult result) { if (result.hasErrors()) { return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; } else { this.owners.save(owner); return "redirect:/owners/" + owner.getId(); } }
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search } // find owners by last name Collection<Owner> results = this.owners.findByLastName(owner.getLastName()); if (results.isEmpty()) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } else { // multiple owners found model.put("selections", results); return "owners/ownersList"; } }
@Override public String toString() { return new ToStringCreator(this) .append("id", this.getId()) .append("new", this.isNew()) .append("lastName", this.getLastName()) .append("firstName", this.getFirstName()) .append("address", this.address) .append("city", this.city) .append("telephone", this.telephone) .toString(); } }