Creating a Repository Interface

We'll cover the following

Defining an interface

Spring’s CrudRepository interface provides all the methods like findById() and save() to fetch from the database or to update the database. All we need to do is define a specialized interface to extend the CrudRepository. Spring Data will generate implementations for interfaces that extend CrudRepository.

Kotlin vs. Java

If we were writing in Java, we’d write something like:

//Java code only for comparison purpose
package com.agiledeveloper.todo;

import org.springframework.data.repository.CrudRepository;

interface TaskRepository extends CrudRepository<Task, Long> { 
}

Get hands-on with 1400+ tech skills courses.