【问题标题】:Cannot convert from Flux<PortCall> to Mono<? extends Object>无法从 Flux<PortCall> 转换为 Mono<?扩展对象>
【发布时间】:2021-05-04 22:44:53
【问题描述】:
public Flux<PortCall> updateByFindById(String gsisKey, PortCall portCall) {
    return portCallRepository.findAllByVesselCode(portCall.getVesselCode())
            .collectList().flatMap(list->{
                return portCallRepository.saveAll(Flux.fromIterable(list));
            });
                    
}

这里我试图调用 SimpleReactiveMongoRepository 的 saveAll() 即 public Flux saveAll(Iterable entity)

【问题讨论】:

  • Flux.fromIterable(list) 返回 FluxsaveAll 采用 Iterable&lt;S&gt;Flux 不是 Iterable。试着打电话给portCallRepository.saveAll(list)。或者只是跳过collectList 并使用save 它仍然只会对数据库进行一次事务。

标签: java-8 spring-webflux reactive-mongo-java


【解决方案1】:

你不想:

public Flux<PortCall> updateByFindById(String gsisKey, PortCall portCall) {
    return portCallRepository.saveAll(
         portCallRepository.findAllByVesselCode(portCall.getVesselCode())
    );
}

【讨论】:

  • 不,我正在尝试更新列表然后保存到数据库中,更新逻辑已被删除以保持问题简洁。
猜你喜欢
  • 2017-12-27
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 2020-01-28
  • 2018-05-05
  • 1970-01-01
  • 2020-10-04
相关资源
最近更新 更多