0
0
Spring Bootframework~10 mins

CRUD methods (save, findById, findAll, delete) in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to save an entity using Spring Data JPA.

Spring Boot
repository.[1](entity);
Drag options to blanks, or click blank then click option'
AfindById
Bsave
Cdelete
DfindAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using findById instead of save
Using delete instead of save
2fill in blank
medium

Complete the code to find an entity by its ID.

Spring Boot
Optional<Entity> result = repository.[1](id);
Drag options to blanks, or click blank then click option'
AfindById
Bsave
Cdelete
DfindAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using save instead of findById
Using findAll instead of findById
3fill in blank
hard

Fix the error in the code to retrieve all entities.

Spring Boot
List<Entity> list = repository.[1]();
Drag options to blanks, or click blank then click option'
Asave
BfindById
CfindAll
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using findById which returns Optional
Using save which saves data
4fill in blank
hard

Fill both blanks to delete an entity by its ID.

Spring Boot
repository.[1]([2]);
Drag options to blanks, or click blank then click option'
AdeleteById
Bsave
Cid
DfindAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using save instead of deleteById
Passing the wrong argument instead of the ID
5fill in blank
hard

Fill all three blanks to save an entity, then find it by ID and delete it.

Spring Boot
repository.[1](entity);
Optional<Entity> found = repository.[2](entity.[3]());
Drag options to blanks, or click blank then click option'
Asave
BfindById
CgetId
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete instead of findById
Using a wrong method to get the ID