3 回答

TA貢獻1784條經驗 獲得超7個贊
通過在用戶 ID 前添加“/”來更改功能
@GET
@Path("/{userId}")
public Response getBook(@PathParam("userId") String id) {
}
此外,如果您使用的是 PathParam,那么您還需要將 url 更改為
http://localhost:8080/Server_war_exploded/user/1
其中 1 是用戶 ID
但是如果你想使用
http://localhost:8080/Server_war_exploded/user?userId=1
然后您需要使用 QueryParams 并按如下方式更改代碼
@GET
public Response getBook(@QueryParam("userId") String id) {
}

TA貢獻1788條經驗 獲得超4個贊
使用這個@Path("/{userId}")
。這會起作用。
網址會像這樣:http://localhost:8080/Server_war_exploded/user/{userId}
例子 :http://localhost:8080/Server_war_exploded/user/1

TA貢獻1963條經驗 獲得超6個贊
@Path("{userId}")
它缺少正則表達式。它如何知道現在的用戶 ID 是什么以及路徑的下一步是什么?
它應該是這樣的(如果你的 id 真的是一個字符串......): @Path("{userId:\\w+}")
添加回答
舉報