24

URL /locations/{locationId}/edit.html をマップしようとしています - このコードで動作するようです:

@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";
  }
}

上記の URL を呼び出すと、例外が発生します。

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

@PathVariable アノテーションを間違った方法で使用していますか?

正しい使い方は?

4

3 に答える 3

38

そのはず@PathVariable("locationId") int locationId

于 2012-01-31T10:26:05.603 に答える
16

あなたはあなたの、例えば、にvalue引数を追加する必要があります@PathVariable

 public String showEditForm(
       @PathVariable("locationId") int locationId,
       Map<String, Object> map) {
    // ...
 }
于 2012-01-31T10:26:35.603 に答える