8

我想DateTime在 Slick 2.0 模型中使用。我使用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,但它似乎不起作用。如何在 Slick 模型类中添加 DateTime?

4

2 回答 2

14

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

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

资料来源:Paul Coghlan (@paulcoghlan) 在此处对 Gist 的评论https://gist.github.com/dragisak/4756344#comment-1211671

于 2015-05-13T15:27:34.007 回答
7

看看https://github.com/tototoshi/slick-joda-mapper或者你必须创建自己的类型映射器

于 2014-03-22T14:34:49.960 回答