我使用以下代码构建了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错误)。
我在做什么错了?
答案 0 :(得分:1)
更改此
@RequestMapping(name = "/edit-soldier/{id}", method = RequestMethod.GET)
到
@RequestMapping(value = "/edit-soldier/{id}", method = RequestMethod.GET)
注意:将名称更改为值
或
@GetMapping("/edit-soldier/{id}")