mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-16 17:09:39 +00:00
Small optimization for empty petId
This commit is contained in:
parent
80fd11067c
commit
cdd925d664
1 changed files with 5 additions and 1 deletions
|
@ -68,11 +68,15 @@ class PetController {
|
||||||
public Pet findPet(@PathVariable("ownerId") int ownerId,
|
public Pet findPet(@PathVariable("ownerId") int ownerId,
|
||||||
@PathVariable(name = "petId", required = false) Integer petId) {
|
@PathVariable(name = "petId", required = false) Integer petId) {
|
||||||
|
|
||||||
|
if (petId == null) {
|
||||||
|
return new Pet();
|
||||||
|
}
|
||||||
|
|
||||||
Owner owner = this.owners.findById(ownerId);
|
Owner owner = this.owners.findById(ownerId);
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new IllegalArgumentException("Owner ID not found: " + ownerId);
|
throw new IllegalArgumentException("Owner ID not found: " + ownerId);
|
||||||
}
|
}
|
||||||
return petId == null ? new Pet() : owner.getPet(petId);
|
return owner.getPet(petId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@InitBinder("owner")
|
@InitBinder("owner")
|
||||||
|
|
Loading…
Reference in a new issue