首页 > 解决方案 > 如何使用 Spring Reactive webflux 在 Mongodb 中保存 excel 文件的数据?

问题描述

我想将我的byte[]数据上传到我的 mongodb 中,但我不知道该怎么做,我可以在非反应式使用中做到这一点,InputStream但我不确定如何在反应式中做到这一点。我尝试了一些东西,但没有奏效。

我的服务方式

public Mono<Void> upload(String id){
          return Repository.findById(id)
                .map(p->{byte[] byte=p.getExcel();return byte;})
                .map(byte -> {
                    InputStream file=new ByteArrayInputStream(byte);
                    List<Data> ex= Helper.exceltodata(file);
                       return DataRepository.saveAll(ex);
                }).switchIfEmpty(Mono.error(new ResponseStatusException(HttpStatus.BAD_REQUEST,"unsuccessful"))).subscribe();
    }

我应该如何正确地做到这一点?

标签: javamongodbspring-bootreactive-programmingspring-webflux

解决方案


推荐阅读