Handling Multiple Query Parameters in Jersey

前端 未结 3 925
萌比男神i
萌比男神i 2020-12-08 04:30

In the web service I\'m working on, I need to implement a URI with query parameters which look like /stats?store=A&store=B&item=C&item=D

To

3条回答
  •  青春惊慌失措
    2020-12-08 05:01

    Some libs like axios js use the square brackets notation when sending a multi-value param request: /stats?store[]=A&store[]=B&item[]=C&item[]=D

    To handle all cases (with or without square brackets) you can add another param like this:

    public String methodImCalling(
      @QueryParam(value = "store") final List store, 
      @QueryParam(value = "store[]") final List storeWithBrackets, 
      @QueryParam(value = "item") final List item,
      @QueryParam(value = "item[]") final List itemWithBrackets) {
    ...
    }
    

    Inspecting each of the arguments checking for null.

提交回复
热议问题