使用@pathparam和@requestmapping获取null

Cre*_*tor 13 spring-boot

我使用spring-boot 1.4.3.RELEASE来创建Web服务,而在给出请求时http://localhost:7211/person/get/ram,我为id属性获取null

@RequestMapping(value="/person/get/{id}", method=RequestMethod.GET, produces="application/json")
    public @ResponseBody Person getPersonById(@PathParam("id") String id) {
        return personService.getPersonById(id);
    }
Run Code Online (Sandbox Code Playgroud)

你可以建议我,有什么我错过的吗?

Dee*_*akV 39

获取路径变量的注释是@PathVariable.看起来你已经使用了@PathParam,这是不正确的.

有关详细信息,请查看此信息:

requestparam-VS-pathvariable


Dex*_*ter 9

正如上面已经提到的答案应该使用 @PathVariable,我想清除@PathVariable 和 @PathParam 之间混淆

大多数人对这一部分感到困惑,因为Spring 和其他其他实现(如 Jersey)对同一事物使用了明显不同的注释

@QueryParam在 Jersey@RequestParamSpring Rest API

@PathParam在 Jersey@PathVariableSpring Rest API