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:
nirsa 2025-04-03 12:19:26 +09:00
parent 332abbcb8a
commit 0bacd0367f
4 changed files with 5 additions and 5 deletions

View file

@ -90,7 +90,7 @@ class OwnerController {
}
@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) {
// allow parameterless GET request for /owners to return all records
if (owner.getLastName() == null) {

View file

@ -119,12 +119,12 @@ class PetController {
}
@GetMapping("/pets/{petId}/edit")
public String initUpdateForm() {
public String initUpdateForm(@PathVariable("petId") int petId) {
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}
@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) {
String petName = pet.getName();

View file

@ -85,7 +85,7 @@ class VisitController {
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
// called
@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) {
if (result.hasErrors()) {
return "pets/createOrUpdateVisitForm";

View file

@ -42,7 +42,7 @@ class VetController {
}
@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
// objects so it is simpler for Object-Xml mapping
Vets vets = new Vets();