PathVariable in Spring Controller

dtrunk :

I'm trying to map the url /locations/{locationId}/edit.html - that seems to work with this code:

@Controller
@RequestMapping( "/locations" )
public class LocationController
{
  @RequestMapping( value = "/{locationId}/edit.html", method = RequestMethod.GET )
  public String showEditForm( Map<String, Object> map, @PathVariable int locationId )
  {
    map.put( "locationId", locationId );
    return "locationform";
  }
}

Call the mentioned url results in an exception:

java.lang.IllegalArgumentException: Name for argument type [int] not available, and parameter name information not found in class file either.

Am I using the @PathVariable Annotation in a wrong way?

How to use it correctly?

Moinul Hossain :

it should be @PathVariable("locationId") int locationId

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PathVariable in Spring Controller

Optional @Pathvariable in REST controller spring 4

Spring MVC : Unable to extract pathvariable value in a controller

Pass parameter to Spring controller using @PathVariable

css doesn't load in jsp called with controller with pathvariable in Spring Boot

Give name to PDF in Spring Controller without using @PathVariable

How to access a PathVariable of a controller specified at class level in Spring?

Spring controller test fails with 404 when @PathVariable is a string

Junit Test cases for Spring MVC controller to check @PathVariable parameters in @RequestMapping

How to unit test a Spring MVC controller using @PathVariable?

Redirect to another controller with a @PathVariable

send Boolean as pathvariable to controller

PathVariable and pathvariable with requestparam endpoints in rest controller

Spring mvc @PathVariable

Spring @PathVariable as a Year

Spring 3 @PathVariable validation

Spring set default PathVariable

Multiple @PathVariable in Spring MVC

@PathVariable Validation in Spring 4

Spring @PathVariable annotation not working

Junit Test cases for Spring MVC 4 controller to check @PathVariable parameters in @RequestMapping

Thymeleaf + Spring how to pass to a controller a @PathVariable from a form select option value

Return string with pathvariable to another controller

Using pathvariable in spring mvc 3

How to pass @PathVariable("timeZoneId") in spring?

ZonedDateTime as PathVariable in Spring REST RequestMapping

Spring @PathVariable get everything after /

@PathVariable problems with encoding - Spring MVC

Spring MVC @PathVariable treated as @RequestParam