programing

@pathparam 및 @requestmapping을 사용하여 null을 가져오는 중

madecode 2023. 4. 1. 23:19
반응형

@pathparam 및 @requestmapping을 사용하여 null을 가져오는 중

spring-boot 1.4.3을 사용하고 있습니다.RELEASE를 사용하여 웹 서비스를 작성하면서http://localhost:7211/person/get/ramid 속성에 대해 null을 받습니다.

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

제가 놓친 게 있나요?

경로 변수를 가져오는 주석은 @PathVariable입니다.@PathParam을 대신 사용한 것 같습니다.이것이잘못되었습니다.

자세한 내용은 다음을 참조하십시오.

requestparam-vs-pathvariable

이미 언급한 @PathVariable을 사용해야 하므로 @PathVariable과 @PathParam의 혼동을 해소해야 한다고 생각했습니다.

대부분의 사람들은 이 부분에 대해 혼란스러워하는데, 스프링과 저지 같은 다른 휴식 구현에서는 같은 에 대해 에 띄게 다른 주석을 사용하기 때문이다.

@QueryParam JerseySpring Rest API에 있습니다.

@PathParam JerseySpring Rest API에 있습니다.

@PathParam 대신 @PathVariable 주석을 사용합니다.

id그래야 한다Long대신String에서.@PathVariable그렇다면...

@RequestMapping(value="/person/get/{id}", method=RequestMethod.GET, produces="application/json")
public @ResponseBody Person getPersonById(@PathVariable("id") Long id) {
    return personService.getPersonById(id);
}

언급URL : https://stackoverflow.com/questions/41657428/getting-null-with-pathparam-and-requestmapping

반응형