Creating a user repository

We will communicate with the database in this repository class. This is a Repository class, and so we annotate it with @Repository. Let's create a Repository class named UserRepository.kt, which extends the JpaRepository.  By extending JpaRepository, this interface will get a set of generic CRUD functions to create, update, delete, and fetch the data. 

Here is the code of the Repository class:

@Repository
interface UserRepository: JpaRepository<UserModel, Long>

Here are some functions we will get from this JPARepository:

  • List<T> findAll(): To fetch all the data
  • List<T> findAll(Sort var1) : To fetch all the data in sort
  • List<T> findAllById(Iterable<ID> var1): To fetch data by ID
  • <S extends T> List<S> saveAll(Iterable<S> var1): To insert data using the list of a data

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.254