我想知道为什么没有patchForEntity
RestTemplate
中提供的方法类同 postForEntity
和 getForEntity
.只有 patchForObject
方法在那里只返回对象但不返回 ResponseEntity
.
获取 ResponseEntity
对于 PATCH
请求,我们必须使用 exchange
RestTemplate
的方法,这没关系,但我真的很好奇为什么 Spring 的人没有提供一个方便的 patchForEntity
方法。
有什么线索吗?
最佳答案
在Spring's GitHub中已经打开了一个类似的问题.引用那里给出的答案:
... While it would be technically possible to introduce a
patchForEntity()
method, analogous to the existinggetForEntity()
andpostForEntity()
methods, there are no plans to introduce new functionality in theRestTemplate
API ...
因此,为了回答您的问题,似乎没有提供此功能的技术原因,只是这样做的优先级不够高,因为正如您在问题中提到的,您可以达到您的效果想使用
exchange
方法。无论如何(这对我来说是新闻),“没有计划在 RestTemplate API 中引入新功能”,因为它将被弃用,取而代之的是 WebClient
,所以赔率是 RestTemplate
永远不会有 patchForEntity()
方法。
关于spring - 为什么没有像 RestTemplate 中的 postForEntity 那样的 patchForEntity 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55323510/