【问题标题】:Micronaut correctly handles io.reactivex.Maybe in Controllers, but how?Micronaut 在控制器中正确处理 io.reactivex.Maybe,但如何处理?
【发布时间】:2021-04-09 01:53:23
【问题描述】:

在我的控制器中,我有:

@Get("/{id}")
fun findById(id: String): Maybe<AccountTransaction> {
    return accountTransactionRepository.findById(ObjectId(id))
}

存储库如下所示:

fun findById(id: ObjectId): Maybe<AccountTransaction> {
    return Flowable.fromPublisher(getCollection().find(Filters.eq("_id", id))).firstElement()
}

如果我传入了无效的 ID,控制器会正确响应 404。太好了!我只是不知道为什么/如何发生。我假设它刚刚被嵌入到 MN 中,它会检查它是否为空。但是有人可以向我解释/确认吗?

【问题讨论】:

    标签: mongodb reactive-programming micronaut


    【解决方案1】:

    我假设它刚刚被嵌入到 MN 中,它会检查它是否是 是否为空。但是有人可以向我解释/确认吗?

    只要控制器操作返回 null 或空的Maybe,就会生成 404。

    更多信息请访问https://docs.micronaut.io/2.4.2/guide/#serverIO

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 2020-11-04
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多