mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 16:25:49 +00:00
Merge remote-tracking branch 'origin/handling_null_pointer_exception_ownerID' into handling_null_pointer_exception_ownerID
# Conflicts: # src/main/java/org/springframework/samples/petclinic/owner/PetController.java
This commit is contained in:
commit
c6b90506af
1 changed files with 2 additions and 12 deletions
|
@ -56,23 +56,13 @@ class PetController {
|
|||
|
||||
@ModelAttribute("owner")
|
||||
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
|
||||
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
if (owner == null) {
|
||||
throw new IllegalArgumentException("Owner ID not found: " + ownerId);
|
||||
}
|
||||
return owner;
|
||||
return this.owners.findById(ownerId);
|
||||
}
|
||||
|
||||
@ModelAttribute("pet")
|
||||
public Pet findPet(@PathVariable("ownerId") int ownerId,
|
||||
@PathVariable(name = "petId", required = false) Integer petId) {
|
||||
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
if (owner == null) {
|
||||
throw new IllegalArgumentException("Owner ID not found: " + ownerId);
|
||||
}
|
||||
return petId == null ? new Pet() : owner.getPet(petId);
|
||||
return petId == null ? new Pet() : this.owners.findById(ownerId).getPet(petId);
|
||||
}
|
||||
|
||||
@InitBinder("owner")
|
||||
|
|
Loading…
Reference in a new issue