The Repository Layer of a Spring Boot Application
The service layer in the middle holds the business logic, and it is also required to communicate with the repository layer to fulfil any data needs as well. The Repository layer of the application will in turn communicate with the database.
In a typical application, The repository layer is where we write all the data access objects
When using Spring Data,
- There’s no need to write data access objects.
- You can use any JPA provider.
- You also get automatic custom queries and manual custom queries.
How Spring Data works
comment class in the application, and there’s a
comment table in the database.
Spring Data is going to do all the hard work getting the comment back and forth.
CRUD Repository Interface
You can create your Repository interface extending the CrudRepository interface which provides some basic crud operations.
Following are all the methods available through the CrudRepository interface
- delete(T entity)
- deleteAll(Iterable<? extends T> entities)
- deleteById(ID id)
- existsById(ID id)
- findById(ID id)
- save(S entity)
- saveAll(Iterable<S> entities)