use*_*909 8 scala jodatime slick slick-2.0
我想DateTime
在Slick 2.0模型中使用.我用jodatime:
我添加了依赖项Build.scala
:
"joda-time" % "joda-time" % "2.3",
"org.joda" % "joda-convert" % "1.6"
Run Code Online (Sandbox Code Playgroud)
然后我做:
class Comment(tag:Tag) extends Table[(Long, Int, Int, String, Int, DateTime)](tag,"Comment"){
def id=column[Long]("ID", O.PrimaryKey)
def rate=column[Int]("rate")
def sub=column[Int]("subject")
def content=column[Int]("cotent")
def user_ID=column[Int]("user")
def time=column[DateTime]("time") //-----------an error here
def * = (id, rate,sub, content, user_ID, time)
}
Run Code Online (Sandbox Code Playgroud)
错误是:
could not find implicit value for parameter tm: scala.slick.ast.TypedType[org.joda.time.LocalDate]
Run Code Online (Sandbox Code Playgroud)
我添加了joda-convert jar但它似乎不起作用.如何在Slick模型类中添加DateTime?
bjf*_*her 14
另一个答案提到了库,但是如果你想创建自己的映射器并将它放在类中,这就是一个这样的例子:
implicit def dateTime =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime)
)
Run Code Online (Sandbox Code Playgroud)
资料来源:Paul Coghlan(@paulcoghlan)对Gist的评论https://gist.github.com/dragisak/4756344#comment-1211671