首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为/{repository}/{id}/{property} Spring-data-rest制作verify If-Match头部?

如何为/{repository}/{id}/{property} Spring-data-rest制作verify If-Match头部?
EN

Stack Overflow用户
提问于 2020-10-14 22:13:17
回答 1查看 85关注 0票数 0

我使用了spring-data-rest,并使用了PUT /{repository}/{id}/{property}这样的请求

代码语言:javascript
复制
Body:
/12
Accept: application/json
Content-Type: text/uri-list
If-Match: 42 (incorrect value)

我希望得到412错误,但返回204。

当我调试时,我发现DispatcherServlet使用HandlerExecutionChain with [org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController#createPropertyReference(RootResourceInformation, HttpMethod, CollectionModel, Serializable, String)] and 3 interceptors,该方法不检查if-match值。

并且只有像PUT,PATCH,DELETE这样的请求才会使用HandlerExecutionChain with [org.springframework.data.rest.webmvc.RepositoryEntityController#patchItemResource(RootResourceInformation, PersistentEntityResource, Serializable, PersistentEntityResourceAssembler, ETag, String)] and 3 interceptors来检查if-match值。

是否可以让spring-data-rest验证PUT、DELETE、PATCH /{repository}/{id}/{property}的值是否匹配

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-14 23:58:23

根据official documentation的说法,Spring Data REST需要一个带有@Version注释的版本字段来实现ETag。

如果要对嵌入属性(字段)进行版本化,如何分别对单个嵌入属性进行版本化?答案是不可能的。

如果您想要对引用的属性(JPA联接)进行版本控制,那么您应该向/{that- property -repository}/{id}而不是/{repository}/{id}发出一个PUT/PATCH/DELETE请求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64355212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档