mar*_*234 4 spring-data-jpa spring-data-rest
刚刚学习springboot(并且从.NET世界开始向Java崭新)
弹簧数据和弹簧数据架过PS课程。一切顺利
与MS SQlServer建立了测试项目连接。创建了一些JPA Repos,并且通过了FindAll通过了单元测试
我在应用程序属性中没有设置base-uri,在浏览其余界面(使用Postman)时,所有内容都显示在/ profile下。
{
"_links": {
"self": {
"href": "http://localhost:8080/profile"
},
"users": {
"href": "http://localhost:8080/profile/users"
},
"tasks": {
"href": "http://localhost:8080/profile/tasks"
}
}
}
Run Code Online (Sandbox Code Playgroud)
第一个问题是/ profile来自哪里?
如果导航到位于localhost:8080 / profile的配置文件链接,则会看到以下内容:
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/profile"
},
"persons" : {
"href" : "http://localhost:8080/profile/persons"
},
"addresses" : {
"href" : "http://localhost:8080/profile/addresses"
}
}
}
Run Code Online (Sandbox Code Playgroud)
要使用您的实体,您必须使用thees链接:
http://localhost:8080/users
http://localhost:8080/tasks
Run Code Online (Sandbox Code Playgroud)
顺便说一下,您可以通过三种方式设置“基本路径” :
spring.data.rest.basePath=/api
http://localhost:8080/users
http://localhost:8080/tasks
Run Code Online (Sandbox Code Playgroud)
RepositoryRestConfigurer@Bean
public RepositoryRestConfigurer repositoryRestConfigurer() {
return new RepositoryRestConfigurerAdapter() {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
}
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
734 次 |
| 最近记录: |