我开始使用playframewok
进行光滑和scala我已经使用play-slick 0.5.0.8
将我的项目配置为使用play 2.2.0我的问题是我无法执行一些基本方法,例如“list,foreach,for {} yield ...”
我尝试了一个独立的例子,它使用相同的光滑版本1.0.1 ??
这是项目构建文件
import sbt._
import Keys._
import play.Project._
object Build extends Build {
val appName = "homePage"
val appVersion = "1.0-ALPHA"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
"com.typesafe.play" %% "play-slick" % "0.5.0.8" ,
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"com.typesafe.slick" %% "slick" % "1.0.1"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// add web app as
playAssetsDirectories <+= baseDirectory / "webapp"
)
}
package model
import java.util.Calendar
import scala.slick.driver.PostgresDriver.simple._
case class Article(id: Long,
content: String,
date: java.sql.Date)
object Articles extends Table[Article]("articles") {
def id = column[Long]("art_id", O.PrimaryKey , O.AutoInc) // This is the primary key column
def content = column[String]("art_content", O.NotNull)
def date = column[java.sql.Date]("art_date", O.NotNull, O.Default(new java.sql.Date(Calendar.getInstance().getTime.getTime)))
def * = id ~ content ~ date <> (Article.apply _, Article.unapply _)
}
这里的代码不起作用
query foreach { case (content, date) =>
println(" " + name + ": " + count)
}
//:: cannot resolve the symbol foreach
same thing for [for , yield]
(for(p <- Props if p.key === k) yield p.value).firstOption
我不知道是什么问题,所以每一个帮助都会受到赞赏。
答案 0 :(得分:2)
import scala.slick.driver.PostgresDriver.simple._
,您尝试调用foreach。
答案 1 :(得分:0)
我应该在我的服务源文件中使用import scala.slick.driver.PostgresDriver.simple._
:
import model._
import scala.slick.lifted.Query
import scala.slick.driver.PostgresDriver.simple._
object ArticlesService {
val PAGE_SIZE :Int = 100
def getPaginatedResult(pageNumber : Int) (implicit s: scala.slick.session.Session)= {
val query= Query(Articles)
query.drop(pageNumber * PAGE_SIZE).take(PAGE_SIZE).list()
}
}