September 2019
Intermediate to advanced
462 pages
11h 3m
English
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.
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> { |
| | } |
The Kotlin code isn’t too different from that: there’s no need for ; or {}, and we replaced extends with :. Let’s write the Kotlin equivalent ...
Read now
Unlock full access