使用hateos将_links,_refs添加到Spring应用程序中

问题描述 投票:0回答:1

我有一个Spring Boot服务文章。我正在使用Spring Data Rest和MongoDB。我在自定义控制器中覆盖findAll()方法。但是在响应中,我缺少_links和页面详细信息。我正在寻找一种在自定义控制器中重写findAll()方法时获取_链接和页面信息的方法。

预期的响应:

"_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服务文章。我正在使用Spring Data Rest和MongoDB。我在自定义控制器中覆盖findAll()方法。但是在响应中,我缺少_links和页面详细信息。我是...

java spring spring-boot spring-data-mongodb spring-data-rest
1个回答
0
投票

在pom.xml中添加以下依赖项或在build.gradle中添加相关的gradle依赖项>>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-hateoas</artifactId>
    <version>2.1.4.RELEASE</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.