PathVariable in Spring Controller

dtrunk picture dtrunk · Jan 31, 2012 · Viewed 35.9k times · Source

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?

Answer

Moinul Hossain picture Moinul Hossain · Jan 31, 2012

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