From 859628d32cb57f0567a3aa7247be5503945e31ea Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Mon, 23 Sep 2024 18:59:49 +0200 Subject: [PATCH] Document newly supported interfaces and update existing examples. Fixes #43391 --- docs/src/main/asciidoc/spring-data-jpa.adoc | 2 ++ docs/src/main/asciidoc/spring-data-rest.adoc | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-data-jpa.adoc b/docs/src/main/asciidoc/spring-data-jpa.adoc index 52c20b03c83e4..b04961054c577 100644 --- a/docs/src/main/asciidoc/spring-data-jpa.adoc +++ b/docs/src/main/asciidoc/spring-data-jpa.adoc @@ -416,7 +416,9 @@ Interfaces that extend any of the following Spring Data repositories are automat * `org.springframework.data.repository.Repository` * `org.springframework.data.repository.CrudRepository` +* `org.springframework.data.repository.ListCrudRepository` * `org.springframework.data.repository.PagingAndSortingRepository` +* `org.springframework.data.repository.ListPagingAndSortingRepository` * `org.springframework.data.jpa.repository.JpaRepository` The generated repositories are also registered as beans so they can be injected into any other bean. diff --git a/docs/src/main/asciidoc/spring-data-rest.adoc b/docs/src/main/asciidoc/spring-data-rest.adoc index e3e95121e920e..e83aeb064e2c1 100644 --- a/docs/src/main/asciidoc/spring-data-rest.adoc +++ b/docs/src/main/asciidoc/spring-data-rest.adoc @@ -327,7 +327,7 @@ The former is used by default, but it is highly recommended to specify which one If a database contains many entities, it might not be a great idea to return them all at once. `PagingAndSortingRepository` allows the `spring-data-rest` extension to access data in chunks. -Replace the `CrudRepository` with `PagingAndSortingRepository` in the `FruitsRepository`: +So, you can extend the `PagingAndSortingRepository`: [source,java] ---- @@ -335,7 +335,7 @@ package org.acme.spring.data.rest; import org.springframework.data.repository.PagingAndSortingRepository; -public interface FruitsRepository extends PagingAndSortingRepository { +public interface FruitsRepository extends CrudRepository, PagingAndSortingRepository { } ---- @@ -362,6 +362,19 @@ Now the `GET /fruits` will accept three new query parameters: `sort`, `page` and For paged responses, `spring-data-rest` also returns a set of link headers that can be used to access other pages: first, previous, next and last. +Additionally, rather than extending both `PagingAndSortingRepository` and `CrudRepository`, you can use `JpaRepository`, which is a higher-level abstraction tailored for JPA. Since `JpaRepository` already extends both `PagingAndSortingRepository` and `CrudRepository`, it can replace `CrudRepository` directly. + +[source,java] +---- +package org.acme.spring.data.rest; + +import org.springframework.data.repository.PagingAndSortingRepository; + +public interface FruitsRepository extends JpaRepository { +} +---- + + ==== Fine tuning endpoints generation This allows user to specify which methods should be exposed and what path should be used to access them.