Spring Data REST - collectionResourceRel与path的区别

17
我正在使用Spring Data REST。 RepositoryRestResource注释有两个不同的字段:pathcollectionResourceRel。这两者之间有什么区别?我无法通过阅读文档弄清楚。 path的描述如下:
  

要导出此资源的路径段。

collectionResourceRel的描述如下:
  

生成到集合资源的链接时要使用的rel值。

在我看过的所有代码示例中,这两个属性都是相同的。它们有任何不同的情况吗?它们之间的实际区别是什么?
1个回答

26

例如,对于实体User,默认值将为:

path = users

itemResourceRel = user

collectionResourceRel = users

示例:

GET /users(路径:users

"_links": { 
        "self": {
            "href": "http://localhost:8080/api/users"
        },
        "users": {  <-- collectionResourceRel
            "href": "http://localhost:8080/api/users"
        }
    }

GET /users/1(路径:users

"_links": {
        "self": {
            "href": "http://localhost:8080/api/users/1"
        },
        "user": { <-- itemResourceRel
            "href": "http://localhost:8080/api/users/1"
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接