如何配置 Spring Data REST 以返回带有模板化 ID 的链接?

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

假设我有一个

User
实体的 Spring 数据存储库。然后,Spring Data REST 在其基本路径中生成以下 HAL JSON:

{
  "_links": {
    "users": {
      "href": "http://localhost:8080/users"
    }
  }
}

我也希望我的客户知道他们可以调用 http://localhost:8080/users/{id} 来获取特定用户(例如,http://localhost:8080/users/25)

如何配置 Spring Data REST 为我的所有实体生成此链接?例如,我希望 Spring Data REST 返回如下内容:

{
  "_links": {
    "users": {
      "href": "http://localhost:8080/users{/id}",
      "templated": true
    }
  }
}
spring spring-boot spring-data-rest spring-hateoas hal
© www.soinside.com 2019 - 2024. All rights reserved.