英文:
How to make verify If-Match header for /{repository}/{id}/{property} Spring-data-rest?
问题
我正在使用spring-data-rest,并像这样发出PUT请求:/{repository}/{id}/{property}
请求体:
/12
接受:application/json
内容类型:text/uri-list
若匹配:42(值不正确)
我预期会收到412错误,但实际返回的是204错误。
在我调试时,我发现DispatcherServlet使用了带有[org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController#createPropertyReference(RootResourceInformation, HttpMethod, CollectionModel, Serializable, String)]和3个拦截器的HandlerExecutionChain,并且该方法不会检查if-Match的值。
只有像这样的请求:PUT、PATCH、DELETE /{repository}/{id}
使用了带有[org.springframework.data.rest.webmvc.RepositoryEntityController#patchItemResource(RootResourceInformation, PersistentEntityResource, Serializable, PersistentEntityResourceAssembler, ETag, String)]和3个拦截器的HandlerExecutionChain,该拦截器会检查if-Match的值。
是否有可能使spring-data-rest在PUT、DELETE、PATCH /{repository}/{id}/{property}
时验证if-Match的值?
英文:
I am using spring-data-rest and do request like PUT /{repository}/{id}/{property}
Body:
/12
Accept: application/json
Content-Type: text/uri-list
If-Match: 42 (incorrect value)
I expect to get 412 error but returned 204.
When I debugged I found out that DispatcherServlet use HandlerExecutionChain with [org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController#createPropertyReference(RootResourceInformation, HttpMethod, CollectionModel, Serializable, String)] and 3 interceptors
and that method does not check if-Match value.
And only requests like: PUT, PATCH, DELETE /{repository}/{id}
use HandlerExecutionChain with [org.springframework.data.rest.webmvc.RepositoryEntityController#patchItemResource(RootResourceInformation, PersistentEntityResource, Serializable, PersistentEntityResourceAssembler, ETag, String)] and 3 interceptors
that check if-Match value.
Is it possible to make spring-data-rest verify if-Match value for PUT, DELETE, PATCH /{repository}/{id}/{property}
?
答案1
得分: 1
Spring Data REST要求一个带有@Version
注解的版本字段以实现ETag,详见官方文档。
如果你想为嵌入式属性(字段)设置版本,如何单独为该嵌入式属性设置版本?答案是否定的。
如果你想为引用属性(JPA连接)设置版本,则应向/{that-property-repository}/{id}
发起PUT/PATCH/DELETE请求,而不是/{repository}/{id}/{property}
。
英文:
Spring Data REST requires a version field annotated with @Version
to achieve ETag, according to the official documentation.
If you want to version an embedded property (field), how can you version that single embedded property individually? The answer is impossible.
If you want to version a referenced property (JPA join), then you should make a PUT/PATCH/DELETE request to /{that-property-repository}/{id} instead of /{repository}/{id}/{property}.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论