我是 MongoDB 和 Reactor 的新手,我正在尝试检索用户及其关联的配置文件 这是 POJO :
public class User {
private @Id String id;
private String login;
private String hashPassword;
@Field("profiles") private List<String> profileObjectIds;
@Transient private List<Profile> profiles; }
public class Profile {
private @Id String id;
private @Indexed(unique = true) String name;
private List<String> roles; }
Run Code Online (Sandbox Code Playgroud)
问题是,如何在 User POJO 中注入配置文件?
我知道我可以放置 @DBRef 并解决问题,但在它的文档中,MongoDB 指定手动 Ref 应该优先于 DB ref。
我看到了两种解决方案:
当我得到它时填写 pojo :
public Mono<User> getUser(String login) {
return userRepository.findByLogin(login)
.flatMap(user -> ??? );
}
Run Code Online (Sandbox Code Playgroud)我应该对profileRepository.findAllById()做一些事情,但我不知道或连接两个发布者,因为配置文件结果取决于用户结果。 …
我想使用@PostFilteron 方法返回Optional。
SpringDefaultMethodSecurityExpressionHandler目前无法处理Optional,但我可以制作一个简单的装饰器并将其转换Optional为Stream. GlobalMethodSecurityConfiguration由于我使用的是无法修改的内部框架,如何在不创建新装饰器的情况下注册这样的装饰器。
还有另一种方法可以做到这一点吗?