Skip to content

Instantly share code, notes, and snippets.

@pulse00
Last active December 20, 2016 13:27
Show Gist options
  • Save pulse00/72fbef0cef3caa364e6f0d3d308f83e0 to your computer and use it in GitHub Desktop.
Save pulse00/72fbef0cef3caa364e6f0d3d308f83e0 to your computer and use it in GitHub Desktop.
// drop spring-data-rest and spring-rest-hateoas into your pom.xml
public interface BookRepository extends MongoRepository<Book, String> {
@Query(" {'name' : { $regex : '.*?0.*', $options: 'i' }} ")
Page<Book> filterBooksByName(@Param("term") String term, Pageable pageable);
}
// curl http://127.0.0.1:8080/book/search/filterBooksByName?term=Potter
{
"_embedded": {
"books": [
{ "name" : "Harry Potter and the Philosopher's Stone" },
{ "name" : "Harry Potter and the Goblet of Fire" },
]},
"_links": {
"next": { "href": "http://127.0.0.1:8080/book/search/filterBooksByName?term=Potter&page=1" }
},
"page": {
"totalPages": 50,
"totalElements": 100,
"pageSize": 2,
"page": 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment