用户和组之间存在多对多关系。我想知道如何更新与 SDR 的这种关系。这是我在阅读文档后到目前为止所尝试的。
curl -X POST -H 'Content-Type: text/uri-list' -d 'http://localhost:8080/rest/users/5' http://localhost:8080/rest/groups/1/users
Run Code Online (Sandbox Code Playgroud)
预期结果:将用户 5 添加到组 1。
实际结果:405 方法不允许。
curl -X PUT -H 'Content-Type: text/uri-list' -d 'http://localhost:8080/rest/users/5' http://localhost:8080/rest/groups/1/users
Run Code Online (Sandbox Code Playgroud)
预期结果:用用户 5 替换组 1 的所有成员。
实际结果:按预期工作。
curl -X PUT -H 'Content-Type: text/uri-list' -d @members.txt http://localhost:8080/rest/groups/1/users
Run Code Online (Sandbox Code Playgroud)
其中文件 members.txt 有:
http://localhost:8080/rest/users/5
http://localhost:8080/rest/users/6
http://localhost:8080/rest/users/7
Run Code Online (Sandbox Code Playgroud)
预期结果:将组 1 的所有成员替换为用户 5、6 和 7。
实际结果:仅添加最后一个用户(在本例中为 7)。
有人可以提供一个关于如何向关联添加单个 URI 的示例吗?此外,如果可能,如何添加或替换与多个 URI 的关联?
考虑一个Person具有name注释为的属性的实体@NotNull。然后是一个简单的PersonRepository,这个 repo 用 Spring Data Rest 公开。
当我POST创建一个 new 时Person,如果name属性是nullaValidationException按预期发生。但是我在客户端上实际得到的是一个内部服务器错误(500),并且该消息是TransactionSystemException在异常链中发生的很晚的消息。
我希望得到的是一个错误请求(400),其中包含实际的ValidationException和所有有用的信息,以便客户可以知道发布的数据有什么问题。
似乎是将自定义的验证与SDR作为解释的方式在这里。但问题是,这不是自定义验证器,而是在要求存储库保存数据时发生的标准 bean 验证。所以我不确定这两者是如何结合在一起的。
所以问题:
非常感谢。