Spring Controller中的PathVariable [英] PathVariable in Spring Controller

查看:271
本文介绍了Spring Controller中的PathVariable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试映射网址/locations/{locationId}/edit.html - 这似乎与此代码一起使用:

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.

我是否以错误的方式使用@PathVariable Annotation?

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

如何正确使用它?

推荐答案

它应该是 @PathVariable( locationId)int locationId

这篇关于Spring Controller中的PathVariable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆