Scala 如何在Slick2.0中使用DateTime?

Scala 如何在Slick2.0中使用DateTime?,scala,jodatime,slick,slick-2.0,Scala,Jodatime,Slick,Slick 2.0,我想在Slick 2.0模型中使用DateTime。我使用jodatime: 我在Build.scala中添加了依赖项: "joda-time" % "joda-time" % "2.3", "org.joda" % "joda-convert" % "1.6" 然后我会: class Comment(tag:Tag) extends Table[(Long, Int, Int, String, Int, DateTime)](tag,"Comment"){ def

我想在Slick 2.0模型中使用
DateTime
。我使用jodatime:

我在
Build.scala
中添加了依赖项:

   "joda-time" % "joda-time"    % "2.3",
   "org.joda"  % "joda-convert" % "1.6"
然后我会:

 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)
}
错误是:

 could not find implicit value for parameter tm: scala.slick.ast.TypedType[org.joda.time.LocalDate]

我添加了joda convert jar,但它似乎不起作用。如何在光滑的模型类中添加日期时间

看一看或者你必须创建你自己的类型映射器

另一个答案提到了库,但是如果你想创建你自己的映射器并将其放在类中,这是一个这样的例子:

implicit def dateTime =
    MappedColumnType.base[DateTime, Timestamp](
      dt => new Timestamp(dt.getMillis),
      ts => new DateTime(ts.getTime)
    )

来源:Paul Coghlan(@paulcoghlan)在这里对Gist的评论

这是最好的回答,公认的解决方案对你有什么帮助?因为,我面临着同样的问题。但是下面的解决方案并没有解决我的问题。你能帮我解决这个问题吗?你能看看这个问题吗。谢谢:(考虑到简单性,这应该是更好的答案。