我正在尝试保存与 Lifts 的 Json 数据提取相关的数据并将其保存到数据库中(通过映射器),但我找不到将片段连接到映射器的位置。代码看起来像这样。
这是一个测试片段。
package com.testjson.snippet
import dispatch._
import net.liftweb.json.JsonParser._
import java.io.{ByteArrayOutputStream}
import com.testjson.model.Done
class HelloWorld {
def howdy = <span>Welcome to hello-lift at {new _root_.java.util.Date}</span>
val http = new Http
val bos = new ByteArrayOutputStream
val myRequest = new Request("http://testing.com/folder/file.json")
val rawdata = http(myRequest >>> bos)
val bs = bos.toString
val json = parse(bs)
implicit val formats = net.liftweb.json.DefaultFormats
case class One(sample1: String, sample2: String, sample3: String)
case class Two(samplea: String, sampleb: String, samplec: String, sampled: String)
case class Three(alpha: Int, beta: Int, charlie: String, delta: String)
case class Done(notice: List[One], header: List[Two], data: List[Three])
json.extract[Done]
}
这里有一个示例模型。
package com.testjson.model
import net.liftweb.http.SHtml
import net.liftweb.common._
import net.liftweb.mapper._
class Done extends LongKeyedMapper[Done] with IdPK {
def getSingleton = Done
object sample1 extends MappedPoliteString(this, 12)
object sample2 extends MappedPoliteString(this, 12)
object sample3 extends MappedPoliteString(this, 56)
object samplea extends MappedPoliteString(this, 12)
object sampleb extends MappedPoliteString(this, 12)
object samplec extends MappedPoliteString(this, 56)
object alpha extends MappedPoliteString(this, 56)
object beta extends MappedInt(this)
object charlie extends MappedInt(this)
object delta extends MappedPoliteString(this, 56)
}
object Done extends Done with LongKeyedMetaMapper[Done]
我浏览了这本书的印刷版、更新的电子书和谷歌群组,但无济于事。我只是在寻找一些帮助,或者可能是一个代码示例来为我指明正确的方向。