【问题标题】:Why there is no patchForEntity method just like postForEntity in RestTemplate?为什么 RestTemplate 中没有类似 postForEntity 的 patchForEntity 方法?
【发布时间】:2019-08-14 20:25:09
【问题描述】:
我想知道为什么RestTemplate 类中没有提供patchForEntity 方法,就像postForEntity 和getForEntity 一样。只有patchForObject 方法只返回对象而不是ResponseEntity。
要获取PATCH 请求的ResponseEntity,我们必须使用RestTemplate 的exchange 方法,这没问题,但我真的很好奇为什么Spring 家伙没有提供方便的@ 987654331@方法。
有什么线索吗?
【问题讨论】:
标签:
spring
rest
spring-boot
controller
resttemplate
【解决方案1】:
Spring's GitHub 中已打开类似问题。引用那里给出的答案:
...虽然在技术上可以引入patchForEntity() 方法,类似于现有的getForEntity() 和postForEntity() 方法,但没有计划在RestTemplate API 中引入新功能...
因此,为了回答您的问题,似乎没有技术原因未提供此功能,只是这样做的优先级不够高,因为正如您在问题中提到的那样,您可以实现使用exchange 方法获得您想要的效果。无论如何(这对我来说是个新闻),“没有计划在 RestTemplate API 中引入新功能”,因为它会被 WebClient 弃用,所以几率是 RestTemplate 永远不会拥有patchForEntity()方法。