SPRING CONCEPTS

Repository

Spring Concepts / Repository

A repository abstracts access to stored domain objects.

Understand the idea

Spring Data creates an implementation of a repository interface at runtime. MongoRepository supplies common operations such as save, findById, and delete. Derived method names describe queries, allowing basic data access without manually writing driver calls.

A concrete example

interface TodoRepository
    extends MongoRepository<Todo, String> {}

findByIdAndOwnerId(id, ownerId)

In the application

PersonalTodoRepository combines id and owner in the database query, which is crucial for user isolation.

save can insert an object without an id. Load an existing record before updating when a missing id must produce 404.

See it in a working stage

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly