[英]How to specify resource and id in REST URI using Jersey
在這里,我想在資源的路徑中指定ID以獲取相應的對象。
例:
考慮我們有10個用戶。 獲取用戶的資源URI路徑為/users
。
現在,我想通過在/users/1234
類的URL中傳遞用戶ID來獲取單個用戶。
如何使用澤西島實現這一目標?
使用@PathParam
。
@GET
@Path("/users/{id}")
public Response getUser(@PathParam int id) {
// Fetch user and return Response.
}
你可以這樣使用:
@Path("/users/{userid}")
public Response getUsr(@PathParam("userid") String userId) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.