无法从Mono转换为Flux
我在尝试下面的代码时遇到了这个错误
public Flux<PortCall> updateByFindById(String gsisKey, PortCall portCall) {
return portCallRepository.findAllByVesselCodeOrderBySequenceNo(portCall.getVesselCode())
.switchIfEmpty(
Mono.error(new DataNotFoundException(HttpStatus.NO_CONTENT, PortCallConstants.ROUTE_NOT_FOUND)))
.collectList().flatMap(list -> {
if (list.size() > 0)
return Mono.just(list)
.switchIfEmpty(Mono.empty());
});
}请建议一种解决方法
发布于 2021-01-28 05:00:29
使用collectList()和检查空列表是多余的,因为如果您的存储库方法没有发出任何元素,它会自动调用switchIfEmpty操作符。
就这样放着吧:
return portCallRepository.findAllByVesselCodeOrderBySequenceNo(portCall.getVesselCode())
.switchIfEmpty(
Mono.error(new DataNotFoundException(HttpStatus.NO_CONTENT, PortCallConstants.ROUTE_NOT_FOUND)));https://stackoverflow.com/questions/65926997
复制相似问题