如何验证/ {repository} / {id} / {property} Spring-data-rest的If-Match标头?

问题描述

我正在使用spring-data-rest,并且会像PUT /{repository}/{id}/{property}

那样进行请求
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 /{repository}/{id}之类的请求才使用HandlerExecutionChain with [org.springframework.data.rest.webmvc.RepositoryEntityController#patchItemResource(RootResourceInformation,PersistentEntityResource,PersistentEntityResourceAssembler,ETag,String)] and 3 interceptors来检查if-Match值。

能否使spring-data-rest验证是否为PUT,DELETE和PATCH /{repository}/{id}/{property}的if-Match值?

解决方法

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

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

如果要版本化引用的属性(JPA连接),则应向/ {that-property-repository} / {id}而不是/ {repository} / {id}发出PUT / PATCH / DELETE请求/ {属性}。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...