[英]Multiple params in Java Rest API JAX-RS - GET Method
我想將多個參數傳遞給我的方法。 我該怎么做呢? 我希望網址看起來像這樣http:// host / one / two / three / four
到目前為止,我有以下代碼
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/{one,two,three}")
public List<Person> getPeople(@PathParam ("one") String one, @PathParam ("two") String two, @PathParam ("three") String three){
String one = one;
String two = two;
String three = three;
}
這是獲取參數並將其傳遞給我的方法的正確語法嗎? 我已經看到@Path中使用了一些正則表達式,但我不明白。 老實說,我真的只希望能夠獲取參數並將它們放入變量(如果可能)中。
固定數量的路徑參數:
@GET
@Path("/{one}/{two}/{three}")
@Produces(MediaType.APPLICATION_JSON)
public Response foo(@PathParam("one") String one,
@PathParam("two") String two,
@PathParam("three") String three) {
...
}
可變數量的路徑參數:
@GET
@Path("/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response foo(@PathParam("path") String path) {
String[] paths = path.split("/");
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.