我想在我的类中获取 url 参数。我的应用程序基于 Spring MVC。
调用 url 时:http://localhost:8080/mywebapp/dir/register.do?id=26
它给出错误 400
@RequestMapping(value = "/register")
public ModelAndView finalPage(@PathVariable("id") Long id) throws NumberFormatException, Exception {
// code...
}
任何人都可以解决我的问题。
最佳答案
你说
I want to fetch url parameter in my class
但是您正在使用 @PathVariable
其中
indicates that a method parameter should be bound to a URI template variable
您的映射中没有名为 id
的 uri 模板变量。
你真正需要的是 @RequestParam
。 documentation解释如何使用它。
关于java - 使用 spring mvc 获取 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26820243/