single.frompublisher订阅并Map到返回类型reactivex java

9rygscc1  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(221)

使用reactivexMap并返回方法中的值,如下所示

public Single<ProductViewModel> Create(ProductViewModel model) {
        Product product = new Product();
        product.setName(model.getName());
        product.setDescription(model.getDescription());
        product.setPrice(model.getPrice());

        return Single.fromPublisher(this.repository.getCollection("product", Product.class)
        .insertOne(product)).map(success -> {
             return new ProductViewModel(
                    success.getInsertedId(),
                    product.getName(),
                    product.getDescription(),
                    product.getPrice());
        });
    }

当我使用.map函数时,记录不会插入到数据库中,但是在.subscribe方法中,记录成功地插入到数据库中。
但是我想Map插入的记录并将值返回给consumer方法。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题