【发布时间】:2020-11-25 16:43:16
【问题描述】:
我一直在Webclient 中搜索补丁方法的示例。我的模型类中有四个字段,我需要更新一个字段(即状态字段),因此我决定使用 Patch 方法。但我在网上没有任何例子。
我在RestTemplate 中有一段代码,这里我需要它在Webclient 中,因为我正在迁移到Webclient。下面的代码如何实现?
public void updateProfile(UpdateProfile profile, String uniqueId) {
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = new MediaType("application", "merge-patch+json");
headers.setContentType(mediaType);
HttpEntity<UpdateProfile> entity = new HttpEntity<>(profile, headers);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
RestTemplate restTemplate = new RestTemplate(requestFactory);
restTemplate.exchange(firebaseUrl+"/"+path+"/" + uniqueId + ".json",
HttpMethod.PATCH, entity, Void.class);
}
【问题讨论】:
标签: spring-boot webclient resttemplate