问题
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