缺少类型为String的方法参数-Spring MVC的URI模板变量'id'

问题描述 投票:0回答:1

我使用以下代码构建了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错误)。

我在做什么错?

spring-mvc request-mapping
1个回答
0
投票

更改此

@PathVariable String id

to

@PathVariable(value="id") String id
© www.soinside.com 2019 - 2024. All rights reserved.