Repository interfaces
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
get a working repository by declaring an interface.
Planned topics
- Extend
JpaRepository<Entity, IdType>; Spring generates the implementation at startup. - You get
findById,findAll,save,deleteById,count, and paging for free. saveinserts a new entity or merges an existing one; for managed entities it is not needed for updates.findByIdreturns anOptional.- Repositories belong to the persistence layer; services use them, controllers do not.
Draft outline details
Demonstration
public interface ProductRepository extends JpaRepository<Product, Long> {
}Check your understanding
Who writes the implementation class?
Show answer
Spring Data, generated at runtime.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.