我最近开始使用Playframework,并使用Play 2.1.1和Slick 1.0.0实现了一个站点.我现在正试图绕着Json写道,因为我想在我的一个控制器中返回Json.
我一直在看几个关于这个主题的参考文献(比如 这个和这一个, 但无法弄清楚我做错了什么.
我有一个看起来像这样的模型:
case class AreaZipcode( id: Int,
zipcode: String,
area: String,
city: String
)
object AreaZipcodes extends Table[AreaZipcode]("wijk_postcode") {
implicit val areaZipcodeFormat = Json.format[AreaZipcode]
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def zipcode = column[String]("postcode", O.NotNull)
def area = column[String]("wijk", O.NotNull)
def city = column[String]("plaats", O.NotNull)
def autoInc = * returning id
def * = id ~ zipcode ~ area ~ city <> (AreaZipcode.apply _, AreaZipcode.unapply _)
}
Run Code Online (Sandbox Code Playgroud)
您可以看到我正在尝试使用的隐式val,但是当我尝试通过执行以下操作返回控制器中的Json时:
Ok(Json.toJson(areas.map(a => Json.toJson(a))))
Run Code Online (Sandbox Code Playgroud)
我在某种程度上仍然面临着这个错误消息:
No …Run Code Online (Sandbox Code Playgroud)