Spring Data Rest Mongo - 如何使用 id 而不是 URI 创建 DBRef?
Spring Data Rest Mongo - how to create a DBRef using an id instead of a URI?
我有以下实体,它引用了另一个实体。
class Foo {
String id;
String name supplierName;
**@DBRef** TemplateSchema templateSchema;
...
}
我希望能够使用以下 JSON(或类似的)来创建新实体。
{
"supplierName": "Stormkind",
"templateSchema": "572878138b749120341e6cbf"
}
...但看起来 Spring 强制您使用这样的 URI:
{
"supplierName": "Stormkind",
"templateSchema": "/template-schema/572878138b749120341e6cbf"
}
有没有办法通过发布 ID 而不是 URI 来创建 DBRef?
谢谢!
在 REST 中,唯一存在的 ID 形式是 URI(因此得名 Unique Resource Identifier)。像 572878138b749120341e6cbf 这样的东西不能识别资源,/template-schema/572878138b749120341e6cbf
可以。
在 HTTP 级别上,实体不存在,只存在由 URI 标识的资源。这就是为什么 Spring Data REST 希望您使用 URI 作为标识符。
我有以下实体,它引用了另一个实体。
class Foo {
String id;
String name supplierName;
**@DBRef** TemplateSchema templateSchema;
...
}
我希望能够使用以下 JSON(或类似的)来创建新实体。
{
"supplierName": "Stormkind",
"templateSchema": "572878138b749120341e6cbf"
}
...但看起来 Spring 强制您使用这样的 URI:
{
"supplierName": "Stormkind",
"templateSchema": "/template-schema/572878138b749120341e6cbf"
}
有没有办法通过发布 ID 而不是 URI 来创建 DBRef?
谢谢!
在 REST 中,唯一存在的 ID 形式是 URI(因此得名 Unique Resource Identifier)。像 572878138b749120341e6cbf 这样的东西不能识别资源,/template-schema/572878138b749120341e6cbf
可以。
在 HTTP 级别上,实体不存在,只存在由 URI 标识的资源。这就是为什么 Spring Data REST 希望您使用 URI 作为标识符。