在 Spring Data REST 中更改资源路径 | 珊瑚贝

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/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9331.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?