0
0
Spring Bootframework~5 mins

Custom query methods by naming convention in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom query method by naming convention in Spring Boot?
It is a method in a Spring Data repository interface whose name follows a pattern that Spring Data understands to create a database query automatically without writing SQL.
Click to reveal answer
intermediate
How does Spring Boot know what query to run from a method name?
Spring Data parses the method name to identify keywords like findBy, countBy, and conditions like And, Or, GreaterThan, then builds the query based on the entity's fields.
Click to reveal answer
beginner
Example: What does the method name findByLastNameAndAgeGreaterThan mean?
It means find all records where the lastName field matches the given value AND the age field is greater than the given number.
Click to reveal answer
intermediate
Can you use custom query methods for sorting and limiting results?
Yes, by adding keywords like OrderBy and using Pageable parameters, you can sort and limit results using naming conventions.
Click to reveal answer
beginner
What happens if a method name does not follow Spring Boot's naming conventions?
Spring Data will throw an error or fail to create the query because it cannot understand how to translate the method name into a database query.
Click to reveal answer
Which prefix is used to create a method that returns a list of entities matching a condition?
AupdateBy
BdeleteBy
CinsertBy
DfindBy
What does the method name countByStatus do?
ADeletes entities with a given status
BCounts entities with a given status
CFinds entities with a given status
DUpdates entities with a given status
Which keyword would you use to combine two conditions in a method name?
AAnd
BOr
CNot
DBetween
How do you specify sorting in a custom query method name?
AAdd 'GroupBy' followed by the field name
BAdd 'SortBy' followed by the field name
CAdd 'OrderBy' followed by the field name
DAdd 'FilterBy' followed by the field name
What will happen if you name a method findAllUsers in a Spring Data repository?
ASpring Data will not recognize it as a query method
BIt will find all users
CIt will delete all users
DIt will update all users
Explain how Spring Boot creates database queries from custom method names in repositories.
Think about how the method name tells Spring Boot what to look for in the database.
You got /5 concepts.
    Describe how you would write a method name to find all records where age is greater than 30 and status is 'active'.
    Combine conditions with 'And' and use comparison keywords.
    You got /5 concepts.