0
0
Spring Bootframework~5 mins

CRUD methods (save, findById, findAll, delete) in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the save method do in Spring Boot's CRUD repository?
The save method adds a new entity or updates an existing one in the database. It returns the saved entity with any generated values like IDs.
Click to reveal answer
beginner
How does findById work in Spring Boot repositories?
It looks for an entity by its unique ID. It returns an Optional that contains the entity if found, or is empty if not found.
Click to reveal answer
beginner
What is the purpose of findAll in Spring Boot CRUD repositories?
It retrieves all entities of a given type from the database and returns them as a list.
Click to reveal answer
beginner
Explain what delete does in Spring Boot CRUD repositories.
The delete method removes an entity from the database. You can delete by passing the entity or by its ID using deleteById.
Click to reveal answer
intermediate
Why is Optional used with findById in Spring Boot?
Optional helps safely handle the case when an entity might not exist. It avoids errors by forcing you to check if the entity is present before using it.
Click to reveal answer
Which CRUD method in Spring Boot is used to add or update an entity?
Asave
BfindById
CfindAll
Ddelete
What does findById return if no entity is found?
AAn empty Optional
BAn empty list
CAn exception
Dnull
Which method retrieves all entities from the database?
Asave
BfindAll
Cdelete
DfindById
How can you delete an entity using Spring Boot CRUD repository?
AOnly by entity ID
BOnly by entity object
CBy calling save with null
DBy entity object or ID
Why is it good to use Optional with findById?
ATo automatically delete missing entities
BTo speed up queries
CTo avoid null pointer errors
DTo return multiple entities
Describe how the save, findById, findAll, and delete methods work in Spring Boot CRUD repositories.
Think about how you add, find, list, and remove items in a real collection.
You got /4 concepts.
    Explain why Optional is useful when using findById in Spring Boot.
    Consider what happens if you look for something that might not be there.
    You got /4 concepts.