首页 > 解决方案 > 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)));
        });
}
}

标签: spring-webfluxproject-reactor

解决方案


推荐阅读