首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scala返回Future[Unit]而不是Future[ContentComponentModel]

scala返回Future[Unit]而不是Future[ContentComponentModel]
EN

Stack Overflow用户
提问于 2017-08-23 09:32:38
回答 1查看 646关注 0票数 0

我有以下代码:

代码语言:javascript
复制
  def getContentComponents: Action[AnyContent] = Action.async {
        val test = contentComponentDTO.list().map { contentComponentsFuture =>
          contentComponentsFuture.foreach(contentComponentFuture =>

            contentComponentFuture.typeOf match {
              case 1 =>
                println("blubb")
              case 5 =>
                contentComponentDTO.getContentComponentText(contentComponentFuture.id.get).map(
                  text => {
                    contentComponentFuture.text = text.text
                    println(text.text)
                    println(contentComponentFuture.text)
                  }
                )
            }
          )

        }

    Future.successful(Ok(Json.obj("contentComponents" -> test)))

  }

我收到了一条错误信息:

.list()方法应该返回一个FutureContentComponentModel

def list(): Future[Seq[ContentComponentModel]] = db.run {

我在这个案子里犯了什么错误?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-23 11:27:38

您的contentComponentsFuture应该是SeqContentComponentModel类型的。在这种情况下,你应该移动

代码语言:javascript
复制
Future.successful(Ok(Json.obj("contentComponents" -> test)))

只进入映射表达式(这是异步的)后循环。

它应该看起来像:

代码语言:javascript
复制
def getContentComponents: Action[AnyContent] = Action.async {
val test = contentComponentDTO.list().map { contentComponents =>
  contentComponents.foreach(contentComponentFuture =>
    contentComponentFuture.typeOf match {
      case 1 =>
        println("blubb")
      case 5 =>
        contentComponentDTO.getContentComponentText(contentComponentFuture.id.get).map(
          text => {
            contentComponentFuture.text = text.text
            println(text.text)
            println(contentComponentFuture.text)
          }
        )
    }
  )
  Future.successful(Ok(Json.obj("contentComponents" -> contentComponents)))
}

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45835922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档