mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
Pet update fix
This commit is contained in:
parent
6148ddd967
commit
588fd808f8
1 changed files with 14 additions and 2 deletions
|
@ -17,6 +17,7 @@ package org.springframework.samples.petclinic.owner;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -42,7 +43,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|||
*/
|
||||
@Controller
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
class PetController {
|
||||
class privatePetController {
|
||||
|
||||
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
|
||||
|
||||
|
@ -146,7 +147,18 @@ class PetController {
|
|||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
owner.addPet(pet);
|
||||
//owner.addPet(pet);
|
||||
|
||||
List<Pet> petlist = owner.getPets();
|
||||
for(int i=0 ; i<petlist.size() ; i++)
|
||||
{
|
||||
if(petlist.get(i).getId().equals(pet.getId()))
|
||||
{
|
||||
petlist.set(i,pet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
|
|
Loading…
Reference in a new issue