@Repository
@RepositoryRestResource(collectionResourceRel = "myEntity", path = "myEntity")
public interface MyEntity Repository extends JpaRepository<MyEntity, Long>, JpaSpecificationExecutor<MyEntity> {
default Page<MyEntity > findByFilters(Map<String, String> filters, Pageable pageable){
// this is a helper class that handles filtering
Specification<MyEntity > spec = new GenericSpecification<>(filters, MyEntity .class);
return findAll(spec, pageable);
}
MyEntity findByName(String name);
}
I’m using SpringDataRest to generate boilerplate CRUD REST endpoints, but for filtering, i have my own logic based on request params, the only solution i found when reading the SpringDataRest docs when it comes to filtering is to declare NamedQueries like findByName
and this generates a {{entityPath}}/search/{{propertyNameUsingReflexion}}
which takes name
as a param.
that’s not enough for my use case.
is there a way to expose my findByFilters
method as an endpoint using SpringDataRest ?
PS : I do not want to create an endpoint in my controllers for each of my entites to do the filtering.