2017-10-04 34 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

希望這會有所幫助。

相關問題