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
<2> This handler plugs in a custom handler for a Spring Data finder method.
41
-
<3> This handler uses the underlying repository to fetch data, but then does some form of post processing before returning the final data set to the client.
42
-
<4> The results need to be wrapped up in a Spring HATEOAS `Resources` object to return a collection but only a `Resource` for a single item.
43
-
<5> Add a link back to this exact method as a `self` link.
44
-
<6> Returning the collection by using Spring MVC's `ResponseEntity` wrapper ensures that the collection is properly wrapped and rendered in the proper accept type.
37
+
<1> `@RepositoryRestController` indicates that this controller targets an existing Spring Data REST route (`/scanners/search`) tied to an exported repository.
38
+
<2> This example uses constructor injection (no `@Autowired` annotation required when there is only one constructor).
39
+
<3> This handler plugs in a custom handler for a Spring Data finder method.
40
+
<4> This handler uses the underlying repository to fetch data, but then does specialized post processing before returning final results to the client.
41
+
<5> The results need to be wrapped in a Spring HATEOAS `Resources` object to return a collection but only a `Resource` for a single item.
42
+
<6> Add a link back to this exact method as a `self` link.
43
+
<7> Returning the collection using Spring MVC's `ResponseEntity` wrapper ensures that the collection is wrapped and rendered in the proper accept type.
45
44
====
46
45
47
46
`Resources` is for a collection, while `Resource` is for a single item. These types can be combined. If you know the links for each item in a collection, use `Resources<Resource<String>>` (or whatever the core domain type is rather than `String`). Doing so lets you assemble links for each item as well as for the whole collection.
48
47
49
48
IMPORTANT: In this example, the combined path is `RepositoryRestConfiguration.getBasePath()` + `/scanners/search/listProducers`.
50
49
51
-
If you are not interested in entity-specific operations but still want to build custom operations underneath `basePath`, such as Spring MVC views, resources, and others, use `@BasePathAwareController`.
50
+
If you are not interested in entity-specific operations that target existing Spring Data REST routes, but still want to build custom operations underneath `basePath`, such as Spring MVC viewsand resources, use `@BasePathAwareController`.
52
51
53
52
WARNING: If you use `@Controller` or `@RestController` for anything, that code is totally outside the scope of Spring Data REST. This extends to request handling, message converters, exception handling, and other uses.
0 commit comments