WebClient Spring put Request返回值始终为``null''

问题描述

我只是无法通过Spring WebClient获得PUT请求。对于我的“患者”实体的属性,总是传递“ null”并将其写入数据库。我究竟做错了什么? (put()直接在我的RESTful服务上工作。没关系。)

控制器

@Autowired
    WebClient webClient;

    @PutMapping(path = "/client/{id}")
    public Mono<Patient> update(Patient patient) {
        return webClient.put()
                .uri("/patient/" + patient.getId())
                .header(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON_VALUE)
                .header(HttpHeaders.ACCEPT,MediaType.APPLICATION_JSON_VALUE).body(Mono.just(patient),Patient.class)
                .retrieve().bodyToMono(Patient.class);
    }

WebClient配置

@Configuration
public class WebClientConfig {

    @Bean
    public WebClient getWebClient() {
        WebClient webClient = WebClient.builder().baseUrl("http://localhost:8080")
                .defaultCookie("cookieKey","cookieValue")
                .defaultHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON_VALUE).build();
        return webClient;
    }

}
{
    "id": 29,"nachname": null,"vorname": null,"geburtsdatum": null
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)