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?
✗ Incorrect
The
save method adds a new entity or updates an existing one.What does
findById return if no entity is found?✗ Incorrect
findById returns an empty Optional if the entity is not found.Which method retrieves all entities from the database?
✗ Incorrect
findAll returns a list of all entities.How can you delete an entity using Spring Boot CRUD repository?
✗ Incorrect
You can delete by passing either the entity object or its ID.
Why is it good to use
Optional with findById?✗ Incorrect
Optional helps avoid null pointer errors by forcing checks for presence.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.