Issue
I am trying to use the @Param annotation for a custom query I built using Spring Data JPA's Query Creation such that when I pass the query parameter ?organizationId=2
, only Tasks will be returned that have an organization ID that match the given param.
@RepositoryRestResource(collectionResourceRel = "tasks", path = "tasks")
public interface TaskRepository extends JpaRepository<Task, Long> {
List<Task> findByOrganizationId(@Param("organizationId") Long organizationId);
}
The problem is that when I visit the the @RepositoryRestResource
path at /tasks?organizationId=2
, it seems to be calling the default List<Task> findAll();
method exposed at /tasks
, and all Tasks are returned.
How can I make Spring direct the request to my custom method?
Solution
All query method resources are exposed under the search resource. (See here for further information.)
http://localhost:8080/tasks/search/
should give you the list of available search endpoints. One should be : http://localhost:8080/tasks/search/findByOrganizationId
, to which you can apply your parameterized search.
Answered By - Marc Tarin