0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.