mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-29 14:49:38 +00:00
cleaned up if statement in controller
This commit is contained in:
parent
5c9ab6bd06
commit
1c9b401248
1 changed files with 8 additions and 7 deletions
|
@ -92,22 +92,23 @@ public class OwnerController {
|
||||||
|
|
||||||
// find owners by last name
|
// find owners by last name
|
||||||
Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName());
|
Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName());
|
||||||
if (results.size() < 1) {
|
if (results.isEmpty()) {
|
||||||
// no owners found
|
// no owners found
|
||||||
result.rejectValue("lastName", "notFound", "not found");
|
result.rejectValue("lastName", "notFound", "not found");
|
||||||
return "owners/findOwners";
|
return "owners/findOwners";
|
||||||
}
|
}
|
||||||
if (results.size() > 1) {
|
else if (results.size() == 1) {
|
||||||
|
// 1 owner found
|
||||||
|
owner = results.iterator().next();
|
||||||
|
return "redirect:/owners/" + owner.getId();
|
||||||
|
}
|
||||||
|
else {
|
||||||
// multiple owners found
|
// multiple owners found
|
||||||
model.put("selections", results);
|
model.put("selections", results);
|
||||||
return "owners/ownersList";
|
return "owners/ownersList";
|
||||||
} else {
|
|
||||||
// 1 owner found
|
|
||||||
owner = results.iterator().next();
|
|
||||||
return "redirect:/owners/" + owner.getId();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
|
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
|
||||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||||
Owner owner = this.clinicService.findOwnerById(ownerId);
|
Owner owner = this.clinicService.findOwnerById(ownerId);
|
||||||
|
|
Loading…
Reference in a new issue