Skip to content

Commit

Permalink
Replaced @RequestMapping annotation with shortcut annotation for requ…
Browse files Browse the repository at this point in the history
…ested HTTP Method
  • Loading branch information
pixeebot[bot] authored Apr 16, 2024
1 parent e59d19d commit 03df36f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
Expand Down Expand Up @@ -55,14 +57,14 @@ public void setAllowedFields(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}

@RequestMapping(value = "/owners/new", method = RequestMethod.GET)
@GetMapping(value = "/owners/new")
public String initCreationForm(Map<String, Object> model) {
Owner owner = new Owner();
model.put("owner", owner);
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}

@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
@PostMapping(value = "/owners/new")
public String processCreationForm(@Valid Owner owner, BindingResult result) {
if (result.hasErrors()) {
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
Expand All @@ -72,13 +74,13 @@ public String processCreationForm(@Valid Owner owner, BindingResult result) {
}
}

@RequestMapping(value = "/owners/find", method = RequestMethod.GET)
@GetMapping(value = "/owners/find")
public String initFindForm(Map<String, Object> model) {
model.put("owner", new Owner());
return "owners/findOwners";
}

@RequestMapping(value = "/owners", method = RequestMethod.GET)
@GetMapping(value = "/owners")
public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {

// allow parameterless GET request for /owners to return all records
Expand All @@ -104,14 +106,14 @@ public String processFindForm(Owner owner, BindingResult result, Map<String, Obj
}


@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
@GetMapping(value = "/owners/{ownerId}/edit")
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
Owner owner = this.owners.findById(ownerId);
model.addAttribute(owner);
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}

@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.POST)
@PostMapping(value = "/owners/{ownerId}/edit")
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId) {
if (result.hasErrors()) {
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.springframework.stereotype.Controller;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

Expand Down Expand Up @@ -76,13 +78,13 @@ public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map<String, Obje
}

// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
@RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET)
@GetMapping(value = "/owners/*/pets/{petId}/visits/new")
public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Object> model) {
return "pets/createOrUpdateVisitForm";
}

// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
@PostMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new")
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
if (result.hasErrors()) {
return "pets/createOrUpdateVisitForm";
Expand Down

0 comments on commit 03df36f

Please sign in to comment.