0

在 RXJava 中映射返回类型

@Queue(ProductTopicConstants.DELETE_PRODUCT)
    public Single<String> Delete(String id) {
        LOG.info(String.format("Listener --> Delete the document from the database"));
        ProductSearchCriteria criteria = new ProductSearchCriteria();
        criteria.setId(id);
        Bson query = QueryBuilder.QueryBuilder(criteria, Bson.class).get(0);
        return  Single.fromPublisher(
                this.repository.getCollection(ProductConstrants.PRODUCT_COLLECTION_NAME, Product.class)
                        .deleteOne(query)).flatMap(item ->{
                            if(item.getDeletedCount() == 0)
                                return Single.just("Success");
                            else
                                return Single.just(id);
        });
    }

现在返回类型是Disposable类型,是否可以转换为其他类型,例如Single<String>我尝试过的flatMapand MAP,但是当我订阅该方法时,它再次转换为Disposable

4

0 回答 0