Change Resource Path in Spring Data REST
使用 Spring Data REST,我想将特定资源的路径更改为前缀,即 http://example.net/api/customprefix/myresource 与 http://example.net/api/myresource
我知道如何使用 application.properties 中的 spring.data.rest.base-path 指令更改我的 Spring Data REST 项目的基本路径,并且当前设置为 /api
我尝试了以下方法,但在 http://example.net/api/customprefix/myresource
得到了 404
1
2 |
@RepositoryRestResource(path =”customprefix/myresource”, collectionResourceRel =”myresources”)
public interface MyResourceRepository extends PagingAndSortingRepository<MyResource, UUID> { } |
是否可以使用 Spring Data REST 为资源或资源组设置自定义前缀?
您想要做的事情不可能通过设计:您可以在此处阅读扩展版本的原因
基本上,您没有理由要这样做,因为服务器或客户端不需要知道或理解您的 URI 的含义。 customprefix 对服务器或客户端没有任何意义。您可以使用驼峰式大小写或类似的东西来使您的 URI 更具可读性。
在你的情况下,即 path =”customprefix-myresource”。
来源:https://www.codenong.com/56449564/