Skip to content

Commit

Permalink
Document newly supported interfaces and update existing examples.
Browse files Browse the repository at this point in the history
Fixes #43391

(cherry picked from commit 859628d)
  • Loading branch information
aureamunoz authored and gsmet committed Sep 25, 2024
1 parent 515e773 commit 4e32c3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/src/main/asciidoc/spring-data-jpa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 15 additions & 2 deletions docs/src/main/asciidoc/spring-data-rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ 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]
----
package org.acme.spring.data.rest;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface FruitsRepository extends PagingAndSortingRepository<Fruit, Long> {
public interface FruitsRepository extends CrudRepository<Fruit, Long>, PagingAndSortingRepository<Fruit, Long> {
}
----

Expand All @@ -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<Fruit, Long> {
}
----


==== Fine tuning endpoints generation

This allows user to specify which methods should be exposed and what path should be used to access them.
Expand Down

0 comments on commit 4e32c3d

Please sign in to comment.