mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 07:45:49 +00:00
- Delete Button for Owners
- on cascade delete for pets
This commit is contained in:
parent
187c4a367c
commit
d37fba0dfc
3 changed files with 16 additions and 6 deletions
|
@ -25,12 +25,7 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
@ -144,6 +139,12 @@ class OwnerController {
|
|||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
@GetMapping("/owners/{ownerId}/delete")
|
||||
public String deleteOwner(@PathVariable("ownerId") int ownerId) {
|
||||
this.owners.deleteOwnerById(ownerId);
|
||||
return "redirect:/owners";
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom handler for displaying an owner.
|
||||
* @param ownerId the ID of the owner to display
|
||||
|
|
|
@ -72,6 +72,9 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
|
|||
*/
|
||||
void save(Owner owner);
|
||||
|
||||
@Transactional
|
||||
void deleteOwnerById(int ownerId);
|
||||
|
||||
/**
|
||||
* Returns all the owners from data store
|
||||
**/
|
||||
|
|
|
@ -34,6 +34,12 @@
|
|||
|
||||
<a th:href="@{__${owner.id}__/edit}" class="btn btn-primary">Edit
|
||||
Owner</a>
|
||||
<a th:href="@{__${owner.id}__/delete}" class="btn btn-primary" th:method="delete">Delete
|
||||
Owner</a>
|
||||
|
||||
|
||||
|
||||
|
||||
<a th:href="@{__${owner.id}__/pets/new}" class="btn btn-primary">Add
|
||||
New Pet</a>
|
||||
|
||||
|
|
Loading…
Reference in a new issue