Spring Data REST: How to get many elements using a list of identifiers in a single call?

I can get one book from Spring Data REST with a call, for example: GET / book / {id}

Now, if I know the identifiers of two books, and I want to get them all at once? What should be the call? I tried the following, but it returns me different books than the ones indicated:

GET /book?ids=id1,id2
+2
source share
1 answer

You can declare a request method in your repository interface as follows:

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

So you can request books this way:

GET /book/search/findByIdIn?ids=1,6,9
+5
source

Source: https://habr.com/ru/post/1548607/


All Articles