Creating CRUD repositories

The Spring Boot Data JPA provides a CrudRepository interface for CRUD operations. It provides CRUD functionalities to our entity class.

We will now create our repository in the domain package, as follows:

  1. Create a new class called CarRepository in the 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> {      }

Our CarRepository now extends the Spring Boot JPA CrudRepository interface. <Car, Long> type arguments define that this is the repository for the Car entity class and the type of the ID field is long.

CrudRepository provides ...

Get Hands-On Full Stack Development with Spring Boot 2.0 and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.