【发布时间】:2023-04-03 16:10:01
【问题描述】:
我有一篇 Spring Boot 服务文章。我正在使用弹簧数据休息和 mongoDB。我正在覆盖自定义控制器中的 findAll() 方法。但在回复中,我缺少 _links 和页面详细信息。当自定义控制器中的 findAll() 方法被覆盖时,我正在寻找一种方法来获取 _links 和页面信息。
预期响应:
"_links": {
"self": {
"href": "http://localhost:8080/article"
},
"profile": {
"href": "http://localhost:8080/profile/articles"
},
"search": {
"href": "http://localhost:8080/articles/search"
},
"page": {
"size": 20,
"totalElements": 61,
"totalPages": 5,
"number": 0
}
}
}
【问题讨论】:
-
您需要添加 spring-boot-starter-hateoas 依赖并相应地执行更改https://www.baeldung.com/spring-hateoas-tutorial。请检查
-
向我们展示您的相关代码,以便我们更好地理解以帮助您
-
您需要确保返回适当的表示。 (指定您的 Spring HATEOAS 的确切版本,因为这在 v1.0 中发生了巨大变化。)
标签: java spring spring-boot spring-data-mongodb spring-data-rest