webflux 是不是很容易写出回调地狱啊
话说原本很简单的一个场景,查询 User 和 UserInfo 的信息,然后复制给 OperInfo
webflux 写出来总感觉怪怪的
// mvc
User user = userRepository.findById(xxx);
UserInfo userInfo = userInfoRepository.findById(xxx);
OperInfo operInfo = new OperInfo();
BeanUtils.copyProperties(user, operInfo);
BeanUtils.copyProperties(userInfo, operInfo);
return operInfo;
我 webflux 写成了下面,不知道应该怎么写才是最佳实践
// webflux
Mono<User> user = userRepository.findById(xxx);
Mono<UserInfo> userInfo = userInfoRepository.findById(xxx);
return Mono.zip(user, userInfo).flatmap(data -> {
User user = data.getT1();
UserInfo userInfo = data.getT2();
OperInfo operInfo = new OperInfo();
BeanUtils.copyProperties(user, operInfo);
BeanUtils.copyProperties(userInfo, operInfo);
return operInfo;
})