在Spring Data REST中更改资源路径

时间:2019-06-04 18:39:38

标签: spring spring-data spring-data-rest

借助Spring Data REST,我想将特定资源的路径更改为前缀,例如http://example.net/api/customprefix/myresourcehttp://example.net/api/myresource

我知道如何使用spring.data.rest.base-path中的application.properties指令更改Spring Data REST项目的基本路径,并且当前设置为{{ 1}}

我尝试了以下操作,但是在/api处得到了404

http://example.net/api/customprefix/myresource

是否可以通过Spring Data REST为一个资源或一组资源设置自定义前缀?

1 个答案:

答案 0 :(得分:1)

根据设计,您无法做的事情是:you can read an extended version of why exactly here

基本上没有理由要这样做,因为服务器或客户端不需要了解或理解URI的含义。 customprefix对服务器或客户端毫无意义。您可以使用驼峰式或类似的方式使URI更具可读性。

在您的情况下,即path = "customprefix-myresource"