Creating repositories

Spring Data JPA has is the ability to create repository implementations automatically, at runtime, from a repository interface. We will see how this works by creating a repository to access the User entities. Create a repositories package and include UserRepository.kt in it:

package com.example.messenger.api.repositoriesimport com.example.messenger.api.models.Userimport org.springframework.data.repository.CrudRepositoryinterface UserRepository : CrudRepository<User, Long> {  fun findByUsername(username: String): User?  fun findByPhoneNumber(phoneNumber: String): User?}

UserRepository extends the CrudRepository interface. The entity type and id type it works with are specified in the generic parameters of CrudRepository ...

Get Kotlin Programming By Example 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.