mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-25 03:42:48 +00:00
modified the updatePet(Pet newPet) method in Owner class
This commit is contained in:
parent
98e5c6e28b
commit
9b582edb67
2 changed files with 7 additions and 8 deletions
|
@ -174,14 +174,13 @@ public class Owner extends Person {
|
|||
|
||||
public void updatePet(Pet newPet)
|
||||
{
|
||||
for(int i=0 ; i<pets.size() ; i++)
|
||||
Pet existingPet = getPet(newPet.getId());
|
||||
|
||||
if(existingPet != null)
|
||||
{
|
||||
Pet existingPet = pets.get(i);
|
||||
if(existingPet.getId().equals(newPet.getId()))
|
||||
{
|
||||
pets.set(i,newPet);
|
||||
break;
|
||||
}
|
||||
existingPet.setName(newPet.getName());
|
||||
existingPet.setBirthDate(newPet.getBirthDate());
|
||||
existingPet.setType(newPet.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ class PetController {
|
|||
if (result.hasErrors()) {
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
|
||||
owner.updatePet(pet);
|
||||
|
||||
this.owners.save(owner);
|
||||
|
|
Loading…
Reference in a new issue