1. Working with Spring Data Repositories - 0 views
-
Typically, your repository interface will extend Repository, CrudRepository or PagingAndSortingRepository. Alternatively, if you do not want to extend Spring Data interfaces, you can also annotate your repository interface with @RepositoryDefinition
-
It allows quick query definition by method names but also custom-tuning of these queries by introducing declared queries as needed.
- ...21 more annotations...
-
The mechanism strips the prefixes find…By, read…By, and get…By from the method and starts parsing the rest of it
-
List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname); // Enables the distinct flag for the query List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname); List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname); // Enabling ignoring case for an individual property List<Person> findByLastnameIgnoreCase(String lastname); // Enabling ignoring case for all suitable properties List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname); // Enabling static ORDER BY for a query List<Person> findByLastnameOrderByFirstnameAsc(String lastname); List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
-
You can combine property expressions with AND and OR. You also get support for operators such as Between, LessThan, GreaterThan, Like for the property expressions
-
The resolution algorithm starts with interpreting the entire part (AddressZipCode) as the property and checks the domain class for a property with that name (uncapitalized). If the algorithm succeeds it uses that property. If not, the algorithm splits up the source at the camel case parts from the right side into a head and a tail and tries to find the corresponding property, in our example, AddressZip and Code.
-
he infrastructure will recognize certain specific types like Pageable and Sort to apply pagination and sorting to your queries dynamically
-
The first method allows you to pass an org.springframework.data.domain.Pageable instance to the query method to dynamically add paging to your statically defined query. Sorting options are handled through the Pageable instance too
-
Spring is instructed to scan com.acme.repositories and all its subpackages for interfaces extending Repository or one of its subinterfaces. For each interface found, the infrastructure registers the persistence technology-specific FactoryBean to create the appropriate proxies that handle invocations of the query methods. Each bean is registered under a bean name that is derived from the interface name, so an interface of UserRepository would be registered under userRepository
-
This postfix defaults to Impl.Example 1.12. Configuration example<repositories base-package="com.acme.repository" /> <repositories base-package="com.acme.repository" repository-impl-postfix="FooBar" />The first configuration example will try to look up a class com.acme.repository.UserRepositoryImpl to act as custom repository implementation, where the second example will try to lookup com.acme.repository.UserRepositoryFoo
-
To exclude an interface that extends Repository from being instantiated as a repository instance, you can either annotate it with @NoRepositoryBean or move it outside of the configured base-package.
-
]In general, the integration support is enabled by using the @EnableSpringDataWebSupport annotation in your JavaConfig configuration class.
-
In case you need multiple Pageables or Sorts to be resolved from the request (for multiple tables, for example) you can use Spring's @Qualifier annotation to distinguish one from another
-
Spring HATEOAS ships with a representation model class PagedResources that allows enrichting the content of a Page instance with the necessary Page metadata as well as links to let the clients easily navigate the pages.