Spring Derived Method Names
Structure of Derived Query Methods in Spring, has 2 main parts separated by the first occurence of “By” keyword.
The first part is called the “introducer”, and the rest is the “criteria”.
Spring Data JPA supports 5 different operations as introducers
- find
- read
- query
- count
- get
Example:
findByName,
queryByName
(keep in mind both the above will fetch the same result)
In case of introducers, we will get 3 different operations, to limit our result set or duplicate our operations:
- distinct
- top
- first
Example:
findTop5ByName,
findDistinctByName
Handling Null:
When we want to compare the null values, then always try to go using the “…IsNull” or “…IsNotNull” as part of method names instead of giving them as arguments.
Getting specific Columns:
If we want to get specific columns, that is partial data from a table, it is advisable to write Projections or Excerpts.
Here is a great article that can explain the above concept very well:
https://www.amitph.com/spring-data-rest-projections-and-excerpts/