mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:05:49 +00:00
commit
36163094bc
2 changed files with 55 additions and 0 deletions
|
@ -61,6 +61,17 @@ class OwnerController {
|
||||||
|
|
||||||
@ModelAttribute("owner")
|
@ModelAttribute("owner")
|
||||||
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
|
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
return ownerId == null ? new Owner()
|
return ownerId == null ? new Owner()
|
||||||
: this.owners.findById(ownerId)
|
: this.owners.findById(ownerId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Owner not found with id: " + ownerId
|
.orElseThrow(() -> new IllegalArgumentException("Owner not found with id: " + ownerId
|
||||||
|
@ -69,11 +80,33 @@ class OwnerController {
|
||||||
|
|
||||||
@GetMapping("/owners/new")
|
@GetMapping("/owners/new")
|
||||||
public String initCreationForm() {
|
public String initCreationForm() {
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/owners/new")
|
@PostMapping("/owners/new")
|
||||||
public String processCreationForm(@Valid Owner owner, BindingResult result, RedirectAttributes redirectAttributes) {
|
public String processCreationForm(@Valid Owner owner, BindingResult result, RedirectAttributes redirectAttributes) {
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
redirectAttributes.addFlashAttribute("error", "There was an error in creating the owner.");
|
redirectAttributes.addFlashAttribute("error", "There was an error in creating the owner.");
|
||||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
|
@ -86,6 +119,17 @@ class OwnerController {
|
||||||
|
|
||||||
@GetMapping("/owners/find")
|
@GetMapping("/owners/find")
|
||||||
public String initFindForm() {
|
public String initFindForm() {
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
return "owners/findOwners";
|
return "owners/findOwners";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,17 @@ class CrashController {
|
||||||
|
|
||||||
@GetMapping("/oups")
|
@GetMapping("/oups")
|
||||||
public String triggerException() {
|
public String triggerException() {
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
|
System.out.println("===============================================");
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue