我有以下內容Scala/Play!代碼:Scala/Play的語法和含義!代碼示例
case class Tweet(from: String, text: String)
implicit val tweetReads = (
(JsPath \ "from_user_name").read[String] ~
(JsPath \ "text").read[String]) (Tweet.apply _)
我關於上面的代碼的語法和意義幾個問題:
- 在什麼類/對象是
~
方法調用呢? Tweet.apply
參數的類別/類型是什麼?
編輯1:完整的源代碼:
package models
import play.api.libs.json._
import play.api.libs.json.util._
import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
import play.api.libs.functional.syntax._
case class Tweet(from: String, text: String)
object Tweet {
implicit val tweetReads = (
(JsPath \ "from_user_name").read[String] ~
(JsPath \ "text").read[String])(Tweet.apply _)
implicit val tweetWrites = (
(JsPath \ "from").write[String] ~
(JsPath \ "text").write[String])(unlift(Tweet.unapply))
}
請添加'play'版本並導入。 – senia
我使用Play! 2.2.1。我已經使用該模型的完整源代碼更新了我的文章。 – balteo