1

With the following Repository:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PeopleRepository extends PagingAndSortingRepository<People, String> {

    @RestResource
    List<People> findByName(@Param("name") String name);

}

URL for findByName is automatically set to /people/search/findByName. But it seems quite verbose, can the URL be configured to /people and query is like /people?name=john ?

CDT
  • 10,165
  • 18
  • 66
  • 97

2 Answers2

2

If you use the QueryDSL extension you can have the query in that format and have the additional benefit of being able to filter by any combination of properties without having to write any query methods:

Configuration (Assuming Maven)

<dependency> 
    <groupId>com.querydsl</groupId> 
    <artifactId>querydsl-apt</artifactId> 
    <version>4.1.4</version>
    </dependency>
<dependency> 
    <groupId>com.querydsl</groupId> 
    <artifactId>querydsl-jpa</artifactId> 
    <version>4.1.4</version> 
</dependency>

Then simply update your repository definition:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PeopleRepository extends PagingAndSortingRepository<People, String>, 
                                               QuerydslPredicateExecutor<People> {


}

You should now be able to filter like:

/people?name=john
/people?name=John&address.town=London 

etc

Alan Hay
  • 22,665
  • 4
  • 56
  • 110
0

You can change the last part of the path (see the doc):

@RestResource(path = "byName", rel = "byName")
List<People> findByName(@Param("name") String name);
/people/search/byName?name=john

For comprehensive implementation with QueryDsl see @AlanHay answer (more info is here)

Cepr0
  • 28,144
  • 8
  • 75
  • 101