首页 > 解决方案 > Spring Boot REST 路径,例如配置文件和用户

问题描述

我有一个带有以下启动器的 Spring Boot 应用程序 在此处输入图像描述 我需要知道为什么我们有这些 REST 端点

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

标签: spring-boot

解决方案


这是因为你有Rest Repositories依赖。

来自Spring Docs

Spring Data REST 为每个导出的存储库提供了一个应用程序级配置文件语义 (ALPS) 文档。它包含有关 RESTful 转换和每个存储库的属性的信息。

Spring Data REST 应用程序的根目录是配置文件链接。假设您有一个包含人员和相关地址的应用程序,根文档将如下所示:

{   
   "_links" : {
     "persons" : {
     "href" : "http://localhost:8080/persons"
    },
     "addresses" : {
     "href" : "http://localhost:8080/addresses"
    },
     "profile" : {
     "href" : "http://localhost:8080/profile" 
    }   
  } 
}

/users是不是因为你可能将它作为一个端点,或者正如评论@marok中提到的那样,它是因为UserRepository以这种方式暴露的。

希望能帮助到你 !


推荐阅读