According to https://stackoverflow.com/a/48504735/2201165 varargs works out of the box (if you would avoid the Pageable
parameter). Because an array and varargs are pretty much the same and you also want to pass a Pageable
to the method, I tried to use arrays:
You can change the parameter to Location[] locations
so that the signature looks like this:
@Query("Select loc from Location loc where loc in :locations")
public Page<Location> searchLocations(Location[] locations, Pageable pageable);
With this, you are able to call the endpoint in the way @alan-hay mentioned in his comment:
curl -X GET "https://localhost:8080/api/v1/stores/search/searchLocations?locations=https://localhost:8080/api/v1/locations/24&locations=https://localhost:8080/api/v1/locations/23"
Here some SQL output to show what's executed:
Hibernate: select location0_.id as id1_0_ from location location0_ where location0_.id in (? , ?) limit ?
Note
Because you are able to access the locations via an own endpoint (http://localhost:8080/api/v1/locations/{locationId}
) it is likely that there is an extra (Spring Data Rest) repository for the locations itself. In this case this is also possible:
public interface LocationRepository extends JpaRepository<Location, Long> {
// Here you are also able to use Long[] instead of List<Long>
public Page<Location> findByIdsIn(List<Long> ids, Pageable pageable);
}
With that, you can search the repository like this
curl -X GET "https://localhost:8080/api/v1/locations/search/findByIdsIn?ids=24,23"