Spring Data JPA Query Methods

Spring Data JPA supports a way to create a query from the method name. Query methods are methods which are declared in the repository interface to perform CRUD operations on a database.

List of Query Methods Expressions

Keyword Expressions Example
And findByFirstnameAndLastname(String firstname, String lastname)
Or Customer findByIdOrEmail(String id, String email)
After, IsAfter List<Customer> findByCreateDateAfter(LocalDateTime createdDate)
Before, isBefore List<Customer> findByCreateDateBefore(LocalDateTime createdDate)
Containing, IsContaining, Contains Customer findByFirstnameContaining(String firstname)
Between, IsBetween List<Customer> findByCreatedDateBetween(LocalDateTime createdDate, LocalDateTime createdDate)
EndingWith, IsEndingWith, EndsWith findByFirstnameEndingWith(String firstnameEndingWith)
exists existsByEmail(String email)
False, IsFalse findByEmailAndDeletedIsFalse(String email, boolean deleted)
GreaterThan, IsGreaterThan findByCreatedDateGreaterThan(LocalDateTime createdDate)
GreaterThanEqual, IsGreaterThanEqual findByCreatedDateGreaterThanEqual(LocalDateTime createdDate)
In, IsIn findByIdIn(List<String> ids)
Is, Equals findByDeletedIsTrue()
IgnoreCase findByFirstnameIqnoreCase(String firstname)
Empty, IsEmpty findByFirstnameEmpty()
NotEmpty, IsNotEmpty findByFirstnameNotEmpty()
NotNull, IsNotNull findByFirstnameNotNull()
Null, IsNull findByFirstnameNull()
LessThan, IsLessThan findByCreatedDateLessThan(LocalDateTime createdDate)
LessThanEqual, IsLessThanEqual findByCreatedDateLessThanEqual(LocalDateTime createdDate)
Like, IsLike findByFirstnameLike(String firstname)
Near, IsNear findByLocationNear(Point point)
Not, IsNot findByLastnameNot(String lastname)
NotIn, IsNotIn findByIdNotIn(String lastname)
NotLike, IsNotLike findByLastnameNotLike(String lastname)
Regex, MatchesRegex, Matches findByLastnameRegex(String regex)
StartingWith, IsStartingWith, StartsWith findByLastnameStartingWith(String startingWith)
True, IsTrue findByDeletedIsTrue()
within, IsWithin findByLocationWithin(Point point, Distance distance)