dtr*_*unk 23 java spring controller path-variables spring-mvc
我正在尝试映射网址/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";
}
}
Run Code Online (Sandbox Code Playgroud)
调用提到的url结果会出现异常:
java.lang.IllegalArgumentException: Name for argument type [int] not available, and parameter name information not found in class file either.
Run Code Online (Sandbox Code Playgroud)
我是否以错误的方式使用@PathVariable Annotation?
如何正确使用?
Moi*_*ain 37
它应该是 @PathVariable("locationId") int locationId
Joh*_*erg 16
您应该将value
参数添加到您的@PathVariable
,例如,
public String showEditForm(
@PathVariable("locationId") int locationId,
Map<String, Object> map) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
31284 次 |
最近记录: |