Creating CRUD repositories
The Spring Boot Data JPA provides a CrudRepository interface for Create, Read, Update, and Delete (CRUD) operations. It provides CRUD functionalities to our entity class.Let's create our repository in the domain
package, as follows:
- Create a new interface called
CarRepository
in thecom.packt.cardatabase.domain
package and modify the file according to the following code snippet:
package com.packt.cardatabase.domain;
import org.springframework.data.repository
.CrudRepository;
public interface CarRepository extends CrudRepository<Car, Long> {
}
CarRepository
now extends the Spring Boot JPA CrudRepository
interface. The <Car, Long>
type arguments define that this is the repository for the Car
entity class and that the type of the ID field is Long
.The CrudRepository
interface provides multiple CRUD methods that we can now start to use. The following table lists the most commonly used methods:
If the method returns only...