
spring 5 webflux 中 dopostandsavelist 方法返回数据的问题
代码中,dopostandsavelist 方法被定义为返回 mono
解决方法
要让 dopostandsavelist 方法返回请求回来的 flatmap 中的 jsonarray,可以采用以下方法:
修改后的代码如下:
public Mono<JSONArray> doPostAndSaveList(String token, Map<String, Object> bodyMap) {
log.info("进入doPost方法");
return WebClient.create(baseUrl)
.post()
.uri(uriBuilder -> uriBuilder.path(uri)
.queryParam("access_token", token)
.build())
.bodyValue(bodyMap)
.retrieve()
.bodyToMono(JSONObject.class)
.subscribeOn(Schedulers.elastic())
.flatMap(jsonObject -> {
JSONArray groupsStr = jsonObject.getJSONArray("group_chat_list");
log.info("groupsStr: {}", groupsStr);
if (groupsStr == null) {
return Mono.empty();
} else {
return Mono.just(groupsStr);
}
});
}以上就是Spring 5 WebFlux 中 doPostAndSaveList 方法返回 null 的问题:如何正确处理 WebClient 响应并返回 JSONArray?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号