我是Play Framework的新手,在Play Framework中创建了数据库连接并犯了一些错误。我在我的模型中创建了数据库,并在编译时显示了一些错误,因为我不知道自己做错了什么。
package models
import anorm._
import play.api.db._
import play.api.Play.current
import play.api.db.DB
case class Contact(id: Long, name: String, emailAddress: String)
object Contact {
def all = {
DB.withConnection { implicit connection =>
SQL("SELECT * FROM Contacts").map { row =>
Contact(
id = row[Long]("id"),
name = row[String]("name"),
emailAddress = row[String]("emailAddress")
)
}
}
}.toList
}
@(Contacts: List[models.Contact])
<html>
<head>
<title>CONTACT</title>
</head>
<body>
@Contacts.map{contact=>
@contact.name
@contact.emailAddress
}
</body>
</html>