Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何自定义SpringDataREST以使用存储库资源的自定义路径?_Spring Boot_Spring Data Jpa_Spring Data_Spring Data Rest_Spring Hateoas - Fatal编程技术网

Spring boot 如何自定义SpringDataREST以使用存储库资源的自定义路径?

Spring boot 如何自定义SpringDataREST以使用存储库资源的自定义路径?,spring-boot,spring-data-jpa,spring-data,spring-data-rest,spring-hateoas,Spring Boot,Spring Data Jpa,Spring Data,Spring Data Rest,Spring Hateoas,我正在使用SPRING DATA REST开发一个微服务,其中我需要子资源,以便只能通过主资源访问,如以下结构: http://localhost:8080/posts http://localhost:8080/posts/1/comments 并像这样直接阻止对子资源的直接访问http://localhost:8080/comments/* 如果评论只能通过相关帖子访问,我在我的存储库中执行了以下操作: @RepositoryRestResource(collectionResourceR

我正在使用SPRING DATA REST开发一个微服务,其中我需要子资源,以便只能通过主资源访问,如以下结构:

http://localhost:8080/posts
http://localhost:8080/posts/1/comments
并像这样直接阻止对子资源的直接访问
http://localhost:8080/comments/*

如果评论只能通过相关帖子访问,我在我的存储库中执行了以下操作:

@RepositoryRestResource(collectionResourceRel=“posts”,path=“posts”)
公共接口PostRepository扩展了分页和排序存储库{
...
}
有关评论:

@RepositoryRestResource(collectionResourceRel=“comments”,path=“comments”)
公共接口CommentRepository扩展了分页和排序存储库{
...
}
现在,默认情况下,当我转到时,SpringDataREST返回以下结果:
http://localhost:8080

{
“id”:1,
“内容”:“一些帖子……”,
“作者”:“abc”,
“_链接”:{
“自我”:{
“href”:”http://localhost:8080/posts/1"
},
“属性”:{
“href”:”http://localhost:8080/posts/1/comments"
}
}
}
现在,如果我想发表评论,我需要执行以下操作:

http://{server:port}/comment方法:POST
{“作者”:“abc”,“内容”:“PQROHSFFSHOFSHOSF”,“发布”:“http://{server:port}/post/1}”
但是,我需要实现的是,发布到这样的url
http://{server:port}/posts/1/comment
,其中POST是根资源而不是像前面路径
http://{server:port}/comment

http://{server:port}/posts/1/注释方法:POST
{“作者”:“abc”,“内容”:“PQROHSFFSHOFSHOSF”,“发布”:“http://{server:port}/post/1}”

我现在知道,如果创建一个自定义的注释
@controller
,这是可能的,但我想使用SPRING DATA REST和Hateoas支持的已经构建的功能。

这是否回答了您的问题?不,不幸的是,这不能解决我的问题。这能回答你的问题吗?不,不幸的是,这不能解决我的问题。