【发布时间】:2016-07-28 02:47:56
【问题描述】:
你好,
def getMessages(code:String,offset:Option[Int]) = Action.async(parse.json){request =>
val forPC = (request.body \ "forPC").asOpt[Boolean]
Talk.findByCode(code).map(_ match{
case Success(talk) =>
val talkId = talk.id
Message.getMessages(talkId=talkId,offset=offset.getOrElse(0), forPC ).map(_ match {
case Seq(Tables.Messages) => Ok("Cool")
case _ => Ok("No")
})
case Failure(e) =>
Logger.error(e.getMessage)
NotAcceptable(Json.toJson(Map(
"error" -> "failed"
)))
})
在我的模型中:
// talks by Code
def findByCode(code: String, conferenceid : Int) = {
val query = talks.filter(talk => talk.conferenceId === conferenceid && talk.code === code)
db.run(query.result.head.asTry)
}
def getMessages(talkId:Int ,offset:Int, forPC: Option[Boolean]) = {
val forPCVal = forPC.getOrElse(false)
//ordering by talkId because it's faster than timestamp
val query = messages.filter(msg => msg.talkId === talkId && msg.forpc === forPCVal ).sortBy(_.idmessage.desc).drop(offset).take(10).result
db.run(query)
}
所以 Play 正在等待 Result (Action) ,并显示此错误:
type mismatch;
found : scala.concurrent.Future[play.api.mvc.Result]
required: play.api.mvc.Result
还有这个:
谁能解释为什么会出现这个错误并给我一些提示来解决它?
谢谢
【问题讨论】:
-
不要发文字截图,用文字代替...
-
我尝试在代码中将 '(' 加粗,但在 Stackoverflow 中是不可接受的!
标签: scala web playframework functional-programming slick