我正在使用Play Framework(版本:2.2.3)运行我的应用程序,它会给出编译错误,例如:找不到值anorm而找不到值jdbc,我不确定它是否已连接到我的数据库设置与否?我检查了question,但仍然没用。请帮助我,我做错了什么?。
我做了以下事情:
build.scala:
import sbt._
object AppBuild extends Build {
val appDependencies = Seq(
jdbc,
"com.google.inject" % "guice" % "3.0",
"javax.inject" % "javax.inject" % "1",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41",
"com.typesafe.play" % "play-iteratees_2.10" % "2.2.3"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// we can add our own project settings
)
}
app.scala:
包装模型
import anorm._
import anorm.SqlParser._
import play.api.db.DB
import play.api.db._
import play.api.Play.current
case class Test(id: Pk[Long], content: String)
object Test {
def create(test: Test): Unit = {
DB.withConnection { implicit connection =>
SQL("insert into test(content) values ({content})").on(
'content -> test.content
).executeUpdate()
}
}
}
plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.3")
app.conf:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/abcdatabase"