spring-webflux - Mono 类型中的方法 flatMap()
问题描述
我有一个返回 Map Mono 的方法,如下所示:
private Mono<Map<String,String>> allLocs(){
return all().collectList()
.flatMap(list -> {
Map<String, String> allData = new HashMap<String, String>();
if (list.size() > 0) {
list.forEach(entry -> {
if(entry.getCountryCode()!=null)
allData.put(entry.getCountryCode(), entry.getCountryName());
});
}
return Mono.just(allData);
});
}
当我尝试在外部方法中使用此地图时,我在 generateComplianceResponse 方法的第 1 行中遇到错误
Error:
The method flatMap() in the type Mono<Map<String,String>> is not applicable for the arguments ((<no-type> entry) -> {})
Code:
private void generateComplianceResponse(Compliance compliance){
allLocs().flatMap(entry-> {
complianceResponse.setCountry(entry.get(complianceResponse.getCompliancePort().substring(0,3)));
});
}
}
解决方案
推荐阅读
- mongodb - MongoEngine中如何判断字段是否为空列表?
- c++ - Gnuradio C++ 模拟 python 块rational_resampler_fff
- java - 在二维数组中查找所有可能的 3 个重复数字的序列
- javascript - 隐藏 div(取决于按下的按钮)
- java - 在铸造,编译器的上下文中,“承诺”一词是什么意思?
- java - JavaFX - 我需要在 forTableColumn() 中为 CheckBoxTableCell 传递什么
- c# - 如何使用 sql server 连接或配置 elasticsearch
- c# - 哈希到 16 个字符
- google-app-engine - 如何在 GCP 应用引擎的 requirements.txt 中放置要安装的 Python 包(使用 apt-get)
- django-viewflow - 是什么导致视图流抛出“发现进程的多个连接实例”