正如标题所示,我有Spring方法实现REST和Spring REST注释@Path
我想获得完整的API签名得到这个方法我的意思是完整的签名 例如有没有办法获得REST API的完整API签名在实现@Path的方法里面实现@Path
@Path("/customer/{id}")
method(String id){}
在有办法,我能得到这样的完整签名:http://host:port/customer/1
的方法内。
正如标题所示,我有Spring方法实现REST和Spring REST注释@Path
我想获得完整的API签名得到这个方法我的意思是完整的签名 例如有没有办法获得REST API的完整API签名在实现@Path的方法里面实现@Path
@Path("/customer/{id}")
method(String id){}
在有办法,我能得到这样的完整签名:http://host:port/customer/1
的方法内。
是的,你可以使用注释@PathParam得到{id}
:
@Path("/customer/{id}")
public method(@PathParam("id") String id) {
// implementation
}
您只需注入UriInfo
和使用方法getAbsolutePath()
。另外,请花一些时间来了解Spring MVC(REST)和Jersey(JAX-RS)之间的区别。你的问题似乎表明你认为他们可能是同一件事,而他们肯定不是。
我认为这可能会回答你的问题。
@Path("/customer/{id}")
@Get
public ResponseEntity<String> getCustomer(
@PathParam("id") String id, HttpServletRequest request) {
System.out.println(request.getRequestURL());
return ResponseEntity.ok(id);
}
随着路径PARAM说法,我们需要添加HttpServletRequest
携带有关特定请求的全部信息。
这里request.getRequestURL()
给出了完整的请求url路径。例如http://localhost:8080/testApp/customer/1
。
希望这会有所帮助。
这不会解决问题,我需要完整的API签名,导致调用该方法,正如我已经解释过的。我需要获得“http:// host:port/customer/1”的完整签名 – user2681668