在另一个请求中使用来自数据库请求的结果单声道的值

Use Value of Result Mono from DB Request in Another Request

我想通过用户名获取用户,将此用户指定为笔记的作者,然后将该笔记保存到数据库中。问题是我得到了一个包含用户的 Mono,但我无法将其分配给用户类型的作者字段。

我想做什么:

noteRepository
    .save(noteMapper
        .fromDTO(noteDTO)
        .apply { owner = userReository
            .findByUsername(userPrincipalService.getCurrentUserPrincipal()
                .map { it.username }) 
        })
userRepository
        // Find the User
        .findByUsername(userPrincipalService.getCurrentUserPrincipal()
                .map { it.username })
        // Map the User to a Note, while setting the note's owner 
        .map { user ->
            noteMapper.fromDTO(noteDTO).apply {
                owner = user
            }
        }
        // Save the Note 
        .flatMap { note -> noteRepository.save(note) }