Spring Data JDBC provides repository-based relational database access for Spring Boot applications. Add its starter, a database driver, and schema initialization to connect domain records with relational tables. section 6.2.1
A typical implementation proceeds as follows:
- Choose a database, such as H2 for an in-memory application or PostgreSQL running through Docker Compose. section 6.2.1 section 7.3.1
- Define schema.sql and data.sql files, configuring spring.sql.init.mode=always when initialization must also run against PostgreSQL. section 7.3.2
- Map a Java record to a table and mark its identifier with @Id. section 7.3.2
- Extend CrudRepository to obtain standard operations and add derived or @Query methods for application-specific retrieval. section 6.2.1 section 7.3.2
package com.example.boardgamebuddy.gamedata;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface GameRepository extends CrudRepository<Game, Long> {
Optional<Game> findBySlug(String slug);
}
Inspect a minimal repository declaration with an added findBySlug query. section 6.2.1


