我想從我的默認數據庫postgres
檢索一行。我已經定義了表格「用戶」。爲什麼編譯失敗並顯示「not found:value Users」?
CONF/application.conf
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5234/postgres"
db.default.user="postgres"
db.default.password=""
控制器/ Application.scala
package controllers
import models.{UsersDatabase, Users}
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok(views.html.index(UsersDatabase.getAll))
}
}
模型/ Users.scala
package models
import java.sql.Date
import play.api.Play.current
import play.api.db.DB
import slick.driver.PostgresDriver.simple._
case class User(
id: Int,
username: String,
password: String,
full_name: String,
email: String,
gender: String,
dob: Date,
joined_date: Date
)
class Users(tag: Tag) extends Table[User](tag, "Users") {
def id = column[Int]("id")
def username = column[String]("username", O.PrimaryKey)
def password = column[String]("password")
def full_name = column[String]("full_name")
def email = column[String]("email")
def gender = column[String]("gender")
def dob = column[Date]("dob")
def joined_date = column[Date]("joined_date")
def * = (id, username, password, full_name, email, gender, dob, joined_date) <> (User.tupled, User.unapply)
}
object UsersDatabase {
def getAll: List[User] = {
Database.forDataSource(DB.getDataSource()) withSession {
Query(Users).list
}
}
}
當訪問http://localhost:9000/
它使編譯錯誤:
[error] .../app/models/Users.scala:36: not found: value Users
[error] Query(Users).list
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
如何妥善解決這個錯誤和訪問數據?
感謝您的大力支持,非常感謝。但運行這給了我更多的錯誤 '[錯誤]發現:play.api.mvc.Result [錯誤] required:slick.driver.PostgresDriver.backend.Session => play.api.mvc.Result [error] (擴展爲)slick.driver.PostgresDriver.backend.SessionDef => play.api.mvc.Result [error] Ok(views.html.index(UsersDatabase.getAll)) [error]^ [error] one錯誤發現 [誤差(編譯:編譯)編譯失敗 [錯誤]應用-' index.scala.html '@(用戶:列表[用戶])
編譯' – surenyonjan它再次感謝。我整理了上面的錯誤。 – surenyonjan
這是什麼?我想將其添加到答案中。 –