You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/repositories.adoc
+25-17Lines changed: 25 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1542,11 +1542,12 @@ You have to populate `thing1_page`, `thing2_page`, and so on.
1542
1542
The default `Pageable` passed into the method is equivalent to a `PageRequest.of(0, 20)`, but you can customize it by using the `@PageableDefault` annotation on the `Pageable` parameter.
1543
1543
1544
1544
[[core.web.pageables]]
1545
-
==== Hypermedia Support for Pageables
1545
+
==== Hypermedia Support for `Page` and `Slice`
1546
1546
1547
-
Spring HATEOAS ships with a representation model class (`PagedResources`) that allows enriching the content of a `Page` instance with the necessary `Page` metadata as well as links to let the clients easily navigate the pages.
1548
-
The conversion of a `Page` to a `PagedResources` is done by an implementation of the Spring HATEOAS `ResourceAssembler` interface, called the `PagedResourcesAssembler`.
1549
-
The following example shows how to use a `PagedResourcesAssembler` as a controller method argument:
1547
+
Spring HATEOAS ships with a representation model class (`PagedModel`/`SlicedModel`) that allows enriching the content of a `Page` or `Slice` instance with the necessary `Page`/`Slice` metadata as well as links to let the clients easily navigate the pages.
1548
+
The conversion of a `Page` to a `PagedModel` is done by an implementation of the Spring HATEOAS `RepresentationModelAssembler` interface, called the `PagedResourcesAssembler`.
1549
+
Similarly `Slice` instances can be converted to a `SlicedModel` using a `SlicedResourcesAssembler`.
1550
+
The following example shows how to use a `PagedResourcesAssembler` as a controller method argument, as the `SlicedResourcesAssembler` works exactly the same:
1550
1551
1551
1552
.Using a PagedResourcesAssembler as controller method argument
1552
1553
====
@@ -1555,36 +1556,38 @@ The following example shows how to use a `PagedResourcesAssembler` as a controll
Enabling the configuration, as shown in the preceding example, lets the `PagedResourcesAssembler` be used as a controller method argument.
1572
-
Calling `toResources(…)` on it has the following effects:
1575
+
Calling `toModel(…)` on it has the following effects:
1573
1576
1574
-
* The content of the `Page` becomes the content of the `PagedResources` instance.
1575
-
* The `PagedResources` object gets a `PageMetadata` instance attached, and it is populated with information from the `Page` and the underlying `PageRequest`.
1576
-
* The `PagedResources` may get `prev` and `next` links attached, depending on the page's state.
1577
+
* The content of the `Page` becomes the content of the `PagedModel` instance.
1578
+
* The `PagedModel` object gets a `PageMetadata` instance attached, and it is populated with information from the `Page` and the underlying `Pageable`.
1579
+
* The `PagedModel` may get `prev` and `next` links attached, depending on the page's state.
1577
1580
The links point to the URI to which the method maps.
1578
1581
The pagination parameters added to the method match the setup of the `PageableHandlerMethodArgumentResolver` to make sure the links can be resolved later.
1579
1582
1580
1583
Assume we have 30 `Person` instances in the database.
1581
-
You can now trigger a request (`GET http://localhost:8080/persons`) and see output similar to the following:
1584
+
You can now trigger a request (`GET http://localhost:8080/people`) and see output similar to the following:
@@ -1599,9 +1602,14 @@ You can now trigger a request (`GET http://localhost:8080/persons`) and see outp
1599
1602
----
1600
1603
====
1601
1604
1605
+
WARNING: The JSON envelope format shown here doesn't follow any formally specified structure and it's not guaranteed stable and we might change it at any time.
1606
+
It's highly recommended to enable the rendering as a hypermedia-enabled, official media type, supported by Spring HATEOAS, like https://docs.spring.io/spring-hateoas/docs/{springHateoasVersion}/reference/html/#mediatypes.hal[HAL].
1607
+
Those can be activated by using its `@EnableHypermediaSupport` annotation.
1608
+
Find more information in the https://docs.spring.io/spring-hateoas/docs/{springHateoasVersion}/reference/html/#configuration.at-enable[Spring HATEOAS reference documentation].
1609
+
1602
1610
The assembler produced the correct URI and also picked up the default configuration to resolve the parameters into a `Pageable` for an upcoming request.
1603
1611
This means that, if you change that configuration, the links automatically adhere to the change.
1604
-
By default, the assembler points to the controller method it was invoked in, but you can customize that by passing a custom `Link` to be used as base to build the pagination links, which overloads the `PagedResourcesAssembler.toResource(…)` method.
1612
+
By default, the assembler points to the controller method it was invoked in, but you can customize that by passing a custom `Link` to be used as base to build the pagination links, which overloads the `PagedResourcesAssembler.toModel(…)` method.
0 commit comments