我是Play框架的新手。 我正在使用带有scala的play framework 2.4。
以下是我的行动
def addEvents = Action { request =>
val body: AnyContent = request.body
body.asFormUrlEncoded.map { form =>
println("Request Body ..... "+ form )
val n = form.get("email").mkString(" ")
val eventList = form.get("eventList")
println("Email ..... "+ n )
println("Event List ..... "+ eventList )
Ok("Wop wop wop")
}.getOrElse {
BadRequest("Bad bad bad")
}
}
当我调用此操作时,我会得到以下请求地图:
Map(email -> ArrayBuffer(maskedinesh@gmail.com), eventList[0].eventId -> ArrayBuffer(767), eventList[0].eventTital -> ArrayBuffer(test), eventList[0].eventLocation -> ArrayBuffer(shevare Maharashtra India), eventList[0].eventStrat -> ArrayBuffer(2014 Nov 18, 12:14:00), eventList[0].eventEnd -> ArrayBuffer(2014 Nov 18, 13:15:00), eventList[0].customerEmail -> ArrayBuffer(taylor@colburnllc.com), eventList[0].customerPhone -> ArrayBuffer(484 604 0064), eventList[0].customerName -> ArrayBuffer(Taylor Colburn),eventList[0].jobDisc -> ArrayBuffer(), eventList[0].jobNote -> ArrayBuffer(), eventList[0].scheduledEventExpectedDuration -> ArrayBuffer(01:01), eventList[1].eventId -> ArrayBuffer(731), eventList[1].eventTital -> ArrayBuffer(plumbing), eventList[1].eventLocation -> ArrayBuffer(205 Nilgiri Bld. Acharya Society Warje Pune India 411 052), eventList[1].eventStrat -> ArrayBuffer(2014 Nov 18, 13:46:00), eventList[1].eventEnd -> ArrayBuffer(2014 Nov 18, 15:00:00), eventList[1].customerEmail -> ArrayBuffer(maskedinesh@gmail.com), eventList[1].customerPhone -> ArrayBuffer(86 00 396875), eventList[1].customerName -> ArrayBuffer(Aaaa Aaaa), eventList[1].jobDisc -> ArrayBuffer(hehe dhhdjsj), eventList[1].jobNote -> ArrayBuffer(), eventList[1].scheduledEventExpectedDuration -> ArrayBuffer(01:00), eventList[2].eventId -> ArrayBuffer(720), eventList[2].eventTital -> ArrayBuffer(test20), eventList[2].eventLocation -> ArrayBuffer(patiala Punjab IN), eventList[2].eventStrat -> ArrayBuffer(2014 Nov 18, 15:12:00), eventList[2].eventEnd -> ArrayBuffer(2014 Nov 18, 16:12:00), eventList[2].customerEmail -> ArrayBuffer(maskedinesh@gmail.com), eventList[2].customerPhone -> ArrayBuffer(9530581235), eventList[2].customerName -> ArrayBuffer(abhishek Bandhu), eventList[2].jobDisc -> ArrayBuffer(just for test), eventList[2].jobNote -> ArrayBuffer(), eventList[2].scheduledEventExpectedDuration -> ArrayBuffer(01:00), eventList[3].eventId -> ArrayBuffer(721), eventList[3].eventTital -> ArrayBuffer(test 12), eventList[3].eventLocation -> ArrayBuffer(shevare), eventList[3].eventStrat -> ArrayBuffer(2014 Nov 18, 17:14:00), eventList[3].eventEnd -> ArrayBuffer(2014 Nov 18, 18:14:00), eventList[3].customerEmail -> ArrayBuffer(maskedinesh@gmail.com), eventList[3].customerPhone -> ArrayBuffer(9921660151), eventList[3].customerName -> ArrayBuffer(Ajit Parabat), eventList[3].jobDisc -> ArrayBuffer(shrift kg k globalfo), eventList[3].jobNote -> ArrayBuffer(), eventList[3].scheduledEventExpectedDuration -> ArrayBuffer(01:00), key -> ArrayBuffer(3c157cef19f872b0c53bbdb3b99e5899))
我的问题是如何阅读这些数据?
val n = form.get("email").mkString(" ")
以上代码给我的结果如下
ArrayBuffer(maskedinesh@gmail.com)
而另一个是
val eventList = form.get("eventList")
它将结果表示为“无”#。
。我如何阅读活动清单?
我如何获得电子邮件价值?
答案 0 :(得分:0)
scala> Map("email" -> collection.mutable.ArrayBuffer("maskedinesh@gmail.com"))
res5: scala.collection.immutable.Map[String,scala.collection.mutable.ArrayBuffer[String]] = Map(email -> ArrayBuffer(maskedinesh@gmail.com))
scala> res5.get("email").get(0)
res6: String = maskedinesh@gmail.com