eg: http://host:port/template/products/?productid=1234,1235 how to implement rest api for the above url where in single queryparam passing multiple values and get the all existing records for the productids
1 Answer
Try something like below to accomplish what you are trying to do:
@RequestMapping(value="/products", method=RequestMethod.GET)
public String getMultipleProductsInfo(@RequestParam List<Long> productIdList) {
String productsInfoAsString = getExistingRecordsForTheProductIds(productIdList);
return productsInfoAsString;
}
Notice the
@RequestParam List productIdList
The comma separated list of product IDs are copied into the productIdList list object. You can either iterate through the list or send it over to the method that is responsible for fetching the results from the datasource, such as your database
Please note that the above code snippet returns the response as String. But you could make your API return a response in other formats too, such as JSON.