如何解决在 Spring Webfux 中压缩 2 个不同的 Mono
public Mono<CarandShip> getCarandShip(Long id) {
Mono<Car> carMono = carService.getCar(id).subscribeOn(Schedulers.elastic());
Mono<Ship> shipMono = shipService.getShip(id).subscribeOn(Schedulers.elastic());
return Mono.zip(carMono,shipMono)
.flatMap(zipMono -> {
return new CarandShip(zipMono.getT1(),zipMono.getT2());
});
IntelliJ 在 return 声明中抱怨:
required type: Mono <CarandShip>
Provided: Mono <Object> no
instance(s) of type variable(s) R exist so that CarandShip conforms to Mono<? extends R>
如何将类型转换为所需的 CarandShip
返回类型?
解决方法
所需类型:Mono 提供:Mono 否 存在类型变量 R 的实例,以便 CarAndShip 符合 单声道扩展 R>
正如例外所说:您没有提供 Mono。
所以要么使用 SELECT table_name,column_name,constraint_name,constraint_type
FROM
(
SELECT a.table_name,a.column_name,a.constraint_name FROM all_cons_columns AS a
WHERE a.owner = '[my_user]'
AND a.table_name NOT LIKE 'APEX%'
AND a.constraint_name NOT LIKE 'BIN%'
ORDER BY a.table_name
) AS x
LEFT JOIN
(
SELECT b.constraint_name,b.constraint_type FROM all_constraints AS b
WHERE b.owner = '[my_user]'
AND b.table_name NOT LIKE 'APEX%'
AND b.constraint_name NOT LIKE 'BIN%'
ORDER BY b.constraint_name
) AS y
ON x.constraint_name = y.constraint_name
而不是 map
:
flatMap
或提供 Mono(可能不是这里的最佳方式):
return Mono.zip(carMono,shipMono)
.map(zipMono -> new CarAndShip(zipMono.getT1(),zipMono.getT2()));
,
在本例中,您应该使用 map()
而不是 flatMap()
,因为您没有返回 Mono
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。