自己写下的第一个scala函数(ps:都是老大教的好)

开始

def chatPacketOrder(page: Int) = Action.async{ implicit request =>
    val cPage = if (page <= 0) {1} else {page}
    val loginRobotId = request.session("robotId")
    var q = Json.obj("robotId" -> loginRobotId,"orderType"-> "chat-packet")
    (for{
      total <- orderCol.count(None)
      orderList <- orderCol.find(q).sort(Json.obj("expireTime" -> -1)).options(QueryOpts(skipN = (cPage - 1) * 10, batchSizeN = 10)).cursor[Order]().collect[List](10)
    } yield {
      println(s"total = ${total}")
      println(orderList.map(o => o.quantity).mkString(","))
      Ok(views.html.user.chatPacketOrder(0, orderList, page, total))
    }).recover{
      case t: Throwable =>
        println(t.getMessage)
        t.printStackTrace()
        Ok("Error: " + t.getMessage)
    }
  }

感受

还是有点懵的


扫描二维码,在手机上阅读!