For the latest stable version, please use Spring Data LDAP 3.4.0!spring-doc.cn

Query Methods

Most of the data access operations you usually trigger on a repository result in a query being run against the LDAP directory. Defining such a query is a matter of declaring a method on the repository interface, as the following example shows:spring-doc.cn

PersonRepository with query methods
interface PersonRepository extends PagingAndSortingRepository<Person, String> {

    List<Person> findByLastname(String lastname);                            (1)

    List<Person> findByLastnameFirstname(String lastname, String firstname); (2)
}
1 The method shows a query for all people with the given lastname. The query is derived by parsing the method name for constraints that can be concatenated with And and Or. Thus, the method name results in a query expression of (&(objectclass=person)(lastname=lastname)).
2 The method shows a query for all people with the given lastname and firstname. The query is derived by parsing the method name. Thus, the method name results in a query expression of (&(objectclass=person)(lastname=lastname)(firstname=firstname)).

The following table provides samples of the keywords that you can use with query methods:spring-doc.cn

Table 1. Supported keywords for query methods
Keyword Sample Logical result

LessThanEqualspring-doc.cn

findByAgeLessThanEqual(int age)spring-doc.cn

(attribute⇐age)spring-doc.cn

GreaterThanEqualspring-doc.cn

findByAgeGreaterThanEqual(int age)spring-doc.cn

(attribute>=age)spring-doc.cn

IsNotNull, NotNullspring-doc.cn

findByFirstnameNotNull()spring-doc.cn

(firstname=*)spring-doc.cn

IsNull, Nullspring-doc.cn

findByFirstnameNull()spring-doc.cn

(!(firstname=*))spring-doc.cn

Likespring-doc.cn

findByFirstnameLike(String name)spring-doc.cn

(firstname=name)spring-doc.cn

NotLike, IsNotLikespring-doc.cn

findByFirstnameNotLike(String name)spring-doc.cn

(!(firstname=name*))spring-doc.cn

StartingWithspring-doc.cn

findByStartingWith(String name)spring-doc.cn

(firstname=name*)spring-doc.cn

EndingWithspring-doc.cn

findByFirstnameLike(String name)spring-doc.cn

(firstname=*name)spring-doc.cn

Containingspring-doc.cn

findByFirstnameLike(String name)spring-doc.cn

(firstname=*name*)spring-doc.cn

(No keyword)spring-doc.cn

findByFirstname(String name)spring-doc.cn

(Firstname=name)spring-doc.cn

Notspring-doc.cn

findByFirstnameNot(String name)spring-doc.cn

(!(Firstname=name))spring-doc.cn