mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:25:50 +00:00
Fix: add explicit names to @RequestParam and @PathVariable annotations
to prevent runtime exception Spring Framework 6+ requires parameter name reflection or explicitly named annotations. This commit adds missing `name = "..."` attributes to all @RequestParam and @PathVariable usages across controller classes. Affected controllers: - OwnerController - PetController - VisitController - VetController This change prevents the following runtime error: IllegalArgumentException: Name for argument of type [int] not specified... The application now builds and runs cleanly with `./gradlew clean build`. Signed-off-by: nirsa <islandtim@naver.com>
This commit is contained in:
parent
332abbcb8a
commit
0bacd0367f
4 changed files with 5 additions and 5 deletions
|
@ -90,7 +90,7 @@ class OwnerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/owners")
|
@GetMapping("/owners")
|
||||||
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
public String processFindForm(@RequestParam(name="page", defaultValue = "1") int page, Owner owner, BindingResult result,
|
||||||
Model model) {
|
Model model) {
|
||||||
// allow parameterless GET request for /owners to return all records
|
// allow parameterless GET request for /owners to return all records
|
||||||
if (owner.getLastName() == null) {
|
if (owner.getLastName() == null) {
|
||||||
|
|
|
@ -119,12 +119,12 @@ class PetController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/pets/{petId}/edit")
|
@GetMapping("/pets/{petId}/edit")
|
||||||
public String initUpdateForm() {
|
public String initUpdateForm(@PathVariable("petId") int petId) {
|
||||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/pets/{petId}/edit")
|
@PostMapping("/pets/{petId}/edit")
|
||||||
public String processUpdateForm(Owner owner, @Valid Pet pet, BindingResult result,
|
public String processUpdateForm(@PathVariable("petId") int petId, Owner owner, @Valid Pet pet, BindingResult result,
|
||||||
RedirectAttributes redirectAttributes) {
|
RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
String petName = pet.getName();
|
String petName = pet.getName();
|
||||||
|
|
|
@ -85,7 +85,7 @@ class VisitController {
|
||||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
|
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
|
||||||
// called
|
// called
|
||||||
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||||
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
|
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable("petId") int petId, @Valid Visit visit,
|
||||||
BindingResult result, RedirectAttributes redirectAttributes) {
|
BindingResult result, RedirectAttributes redirectAttributes) {
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
return "pets/createOrUpdateVisitForm";
|
return "pets/createOrUpdateVisitForm";
|
||||||
|
|
|
@ -42,7 +42,7 @@ class VetController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/vets.html")
|
@GetMapping("/vets.html")
|
||||||
public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) {
|
public String showVetList(@RequestParam(name="page", defaultValue = "1") int page, Model model) {
|
||||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||||
// objects so it is simpler for Object-Xml mapping
|
// objects so it is simpler for Object-Xml mapping
|
||||||
Vets vets = new Vets();
|
Vets vets = new Vets();
|
||||||
|
|
Loading…
Reference in a new issue