-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
[[query-by-example.running]] | ||
== Running an Example | ||
|
||
In Spring Data JDBC, you can use Query by Example with Repositories, as shown in the following example: | ||
|
||
.Query by Example using a Repository | ||
==== | ||
[source, java] | ||
---- | ||
public interface PersonRepository | ||
extends CrudRepository<Person, String>, | ||
QueryByExampleExecutor<Person> { … } | ||
public class PersonService { | ||
@Autowired PersonRepository personRepository; | ||
public List<Person> findPeople(Person probe) { | ||
return personRepository.findAll(Example.of(probe)); | ||
} | ||
} | ||
---- | ||
==== | ||
|
||
NOTE: Currently, only `SingularAttribute` properties can be used for property matching. | ||
|
||
The property specifier accepts property names (such as `firstname` and `lastname`). You can navigate by chaining properties together with dots (`address.city`). You can also tune it with matching options and case sensitivity. | ||
|
||
The following table shows the various `StringMatcher` options that you can use and the result of using them on a field named `firstname`: | ||
|
||
[cols="1,2", options="header"] | ||
.`StringMatcher` options | ||
|=== | ||
| Matching | ||
| Logical result | ||
|
||
| `DEFAULT` (case-sensitive) | ||
| `firstname = ?0` | ||
|
||
| `DEFAULT` (case-insensitive) | ||
| `LOWER(firstname) = LOWER(?0)` | ||
|
||
| `EXACT` (case-sensitive) | ||
| `firstname = ?0` | ||
|
||
| `EXACT` (case-insensitive) | ||
| `LOWER(firstname) = LOWER(?0)` | ||
|
||
| `STARTING` (case-sensitive) | ||
| `firstname like ?0 + '%'` | ||
|
||
| `STARTING` (case-insensitive) | ||
| `LOWER(firstname) like LOWER(?0) + '%'` | ||
|
||
| `ENDING` (case-sensitive) | ||
| `firstname like '%' + ?0` | ||
|
||
| `ENDING` (case-insensitive) | ||
| `LOWER(firstname) like '%' + LOWER(?0)` | ||
|
||
| `CONTAINING` (case-sensitive) | ||
| `firstname like '%' + ?0 + '%'` | ||
|
||
| `CONTAINING` (case-insensitive) | ||
| `LOWER(firstname) like '%' + LOWER(?0) + '%'` | ||
|
||
|=== |