How to use List in endpoint exported by Spring Data REST?

时间秒杀一切 提交于 2019-12-22 14:37:22

问题


I have 2 objects, Foo and Bar (a Foo is @ManyToOne with Bar), and a very basic repository interface in Spring Boot 2.0, and a method:

   List<Foo> findByBarIn(@Param("bar") List<Bar> bar);

This gets mapped by Spring to an endpoint called /foos/search/findByBarIn

I can specify a single bar doing something like

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33 (where 33 is the ID the of the Bar entity)

But, how can I specify multiple bars?

I've tried: (with no success)

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33,http://host/bars/44

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33&bar=http://host/bars/44


回答1:


I've found out how to do it:

So, this prototype didn't work:

List<Foo> findByBarIn(@Param("bar") List<Bar> bars);

but this does:

List<Foo> findByBarIn(@Param("bar") Bar... bars);

And then, I can specify multiple bars by:

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33&bar=http://host/bars/44


来源:https://stackoverflow.com/questions/48489674/how-to-use-list-in-endpoint-exported-by-spring-data-rest

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