简体   繁体   中英

Effectively way of handling multiple parameters as input in GET Request

I have a URI

http://our.api.com/Search?term=pumas&filters={"productType":["Clothing","Bags"],"color":["Black","Red"]}

or

http://our.api.com/Search?term=pumas&productType=["Clothing","Bags"]&color=["Black","Red"]

What should be my Input parameter in @GetMapping in Rest-api in Java, I tried using @RequestParam

Change the Uri to

http://our.api.com/Search?term=pumas&productType=Clothing,Bags&color=Black,Red

And in the controller use

@RequestParam(name = "productType") List<String> productTypes, @RequestParam(name = "color") List<String> colors

You can take a look at this post: Correct way to pass multiple values for same parameter name in GET request

There's no standard for what you are asking for, but you can take an argument as comma-separated values and split them in Java, or something like that. For example:

my.api.com/search?color=black,red,yellow,orange

or

my.api.com/search?color=black&color=red&color=yellow&color=orange

There also is a comment I really like, that says that the first approach (csv) should be used as OR (I want to search either black, either red, either yellow, either orange objects), and the second approach should be used as an AND (I want an object which is black, red, yellow AND orange, all of them). That comment is the following one: "A would suggest using id=a&id=b as boolean AND, and id=a,b as boolean OR. – Alex Skrypnyk May 7 '16 at 5:13" (on the checked answer).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM