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

霸气de小男生 提交于 2019-12-07 17:45:33

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/27013726/spring-data-rest-how-to-retrieve-many-items-using-list-of-ids-in-one-single-cal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!