字符串类型的方法参数缺少 URI 模板变量 'id' - Spring MVC
Missing URI template variable 'id' for method parameter of type String - Spring MVC
我使用以下代码构建了一个 Spring MVC 控制器:
@RequestMapping(name = "/edit-soldier/{id}", method = RequestMethod.GET)
public ModelAndView editSoldierForm(@PathVariable String id) throws FileNotFoundException {
System.out.println("id:" + id);
(snip ...)
}
当我使用以下 URL 调用控制器时:http://myurl/edit-soldier/Q65683623,
我收到以下错误:
There was an unexpected error (type=Internal Server Error, status=500).
Missing URI template variable 'id' for method parameter of type String
org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'id' for method parameter of type String
我尝试用值或路径替换名称,但它也不起作用(我这次收到 404 错误)。
我做错了什么?
改变这个
@RequestMapping(name = "/edit-soldier/{id}", method = RequestMethod.GET)
到
@RequestMapping(value = "/edit-soldier/{id}", method = RequestMethod.GET)
Note: Change name to value
或
@GetMapping("/edit-soldier/{id}")
我使用以下代码构建了一个 Spring MVC 控制器:
@RequestMapping(name = "/edit-soldier/{id}", method = RequestMethod.GET)
public ModelAndView editSoldierForm(@PathVariable String id) throws FileNotFoundException {
System.out.println("id:" + id);
(snip ...)
}
当我使用以下 URL 调用控制器时:http://myurl/edit-soldier/Q65683623,
我收到以下错误:
There was an unexpected error (type=Internal Server Error, status=500).
Missing URI template variable 'id' for method parameter of type String
org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'id' for method parameter of type String
我尝试用值或路径替换名称,但它也不起作用(我这次收到 404 错误)。
我做错了什么?
改变这个
@RequestMapping(name = "/edit-soldier/{id}", method = RequestMethod.GET)
到
@RequestMapping(value = "/edit-soldier/{id}", method = RequestMethod.GET)
Note: Change name to value
或
@GetMapping("/edit-soldier/{id}")