-
-
Save Xanaxiel/5c0022b01ed8cf668385caec967a2ec9 to your computer and use it in GitHub Desktop.
Revisions
-
odrotbohm revised this gist
Jul 15, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,6 @@ GET /stores?name=Foo will return all stores with a name of "Foo". A plain `equals(…)` comparison might be a bit strict, so we expose a `QuerydslBinderCustomizer` interface that will allow you to customize the way properties are bound within the overall predicate. As you can see above, the easiest way to define customized bindings is by implementing `customize(…)` in a default method and use the provided `QuerydslBindings` and entity path to tweak the binding as you like. You see we define the city to be bound via `endsWith(…)`, `String` properties in general are bound via a `contains(…)` to make the resulting predicate less restrictive. A working example can be found in https://github.com/spring-projects/spring-data-examples/blob/querydsl-binding/rest/starbucks/src/main/java/example/stores/StoreRepository.java[this feature branch] of the Spring Data Examples repository. -
odrotbohm revised this gist
Jul 15, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ public interface StoreRepository extends PagingAndSortingRepository<Store, String>, QueryDslPredicateExecutor<Store>, QuerydslBinderCustomizer<QStore> { @RestResource(rel = "by-location") Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); default void customize(QuerydslBindings bindings, QStore store) { bindings.bind(store.address.city).single((path, value) -> path.startsWith(value)); bindings.bind(String.class).single((StringPath path, String value) -> path.contains(value)); } } -
odrotbohm created this gist
Jul 15, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ public interface StoreRepository extends PagingAndSortingRepository<Store, String>, QueryDslPredicateExecutor<Store>, QuerydslBinderCustomizer<QStore> { @RestResource(rel = "by-location") Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); default void customize(QuerydslBindings bindings, QStore store) { bindings.bind(store.address.city).single((path, value) -> path.startsWith(value)); bindings.bind(String.class).single((StringPath path, String value) -> path.contains(value)); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ We're just experimenting with some Spring Data / Spring MVC integration that will allow you to bind property path expressions in the request to a Querydsl `Predicate` as a Spring MVC controller method argument. This is cool for manually implemented controllers so I wondered what it takes to integrate that with Spring Data REST. In the example above you see `StoreRepository` extending `QuerydslPredicateExecutor<Store>`. In the coming version of Spring Data REST, this will cause the collection resource exposed for the repository to accept property based filtering: ``` GET /stores?name=Foo ``` will return all stores with a name of "Foo". A plain `equals(…)` comparison might be a bit strict, so we expose a `QuerydslBinderCustomizer` interface that will allow you to customize the way properties are bound within the overall predicate. As you can see above, the easiest way to define customized bindings is by implementing `customize(…)` in a default method and use the provided `QuerydslBindings` and entity path to tweak the binding as you like. You see we define the city to be bound via `endsWith(…)`, `String` properties in general are bound via a `contains(…)` to make the resulting predicate less restrictive.