gpt4 book ai didi

java - Spring Controller 中的 PathVariable

转载 作者:IT老高 更新时间:2023-10-28 13:47:54 24 4
gpt4 key购买 nike

我正在尝试映射 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 注解?

如何正确使用?

最佳答案

应该是 @PathVariable("locationId") int locationId

关于java - Spring Controller 中的 PathVariable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9077831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com