【发布时间】:2022-01-27 21:18:32
【问题描述】:
我正在尝试将此方法转换为响应式方法
@GetMapping(RestConstants.BASE_PATH_AUDIENCE + "/link")
public List<String> users () {
List<String> list= new ArrayList<>();
MongoCollection mongoCollection = mongoTemplate.getCollection("collection");
DistinctIterable distinctIterable = mongoCollection.distinct("user_name", String.class);
MongoCursor mongoCursor = distinctIterable.iterator();
while (mongoCursor.hasNext()){
String user = (String)mongoCursor.next();
creatorsList.add(user);
}
return list;
}
我有类似的东西,但我不知道如何转换 ArrayList 以返回 Mono
@GetMapping(RestConstants.BASE_PATH_AUDIENCE + "/link")
public Mono<List<String>> usersReactive () {
List<Mono<String>> list= new ArrayList<List>();
MongoCollection mongoCollection = mongoTemplate.getCollection("collection");
DistinctIterable distinctIterable = mongoCollection.distinct("user_name", String.class);
MongoCursor mongoCursor = distinctIterable.iterator();
while (mongoCursor.hasNext()){
String user = (String)mongoCursor.next();
list.add(user);
}
return list;
}
【问题讨论】:
-
您确定您想要的是
Mono<List<String>>,而不是Flux<String>? -
相关且可能有帮助,但我不确定它是否重复:stackoverflow.com/questions/63556833/…
标签: java spring reactive-programming spring-webflux