2017-10-04 131 views

回答

2

是的,你可以使用注释@PathParam得到{id}

@Path("/customer/{id}") 
public method(@PathParam("id") String id) { 
    // implementation 
}  
+0

这不会解决问题,我需要完整的API签名,导致调用该方法,正如我已经解释过的。我需要获得“http:// host:port/customer/1”的完整签名 – user2681668

0

您只需注入UriInfo和使用方法getAbsolutePath()。另外,请花一些时间来了解Spring MVC(REST)和Jersey(JAX-RS)之间的区别。你的问题似乎表明你认为他们可能是同一件事,而他们肯定不是。

0

我认为这可能会回答你的问题。

@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

希望这会有所帮助。

相关问题