Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data REST: How to retrieve many items using list of Ids in one single call?

I can retrieve one single book from Spring Data REST with a call such as: GET /book/{id}

Now, if I know the Ids of two books and I want to retrieve them all at once? What should the call be? I tried the following but it is returning me different books than the specified ones:

GET /book?ids=id1,id2
like image 871
Klaus Avatar asked Sep 17 '25 18:09

Klaus


1 Answers

You could declare a query method in your Repository interface like this:

List<Book> findByIdIn(@Param("ids") Long[] ids);

So that you can request books this way:

GET /book/search/findByIdIn?ids=1,6,9
like image 115
Jean Duarte Avatar answered Sep 20 '25 09:09

Jean Duarte