伙计们,我正在尝试从 mysql 数据库中获取一些结果,但将其提取到 scala.html 文件时出错。这是我的代码:
/*Customers.scala. Its controller*/
package controllers
import play.api._
import play.api.mvc._
import models.Customers
object Customers extends Controller{
def customer = Action{
val nb_customers = Customers.allCustomers
Ok(views.html.customer(nb_customers)) //I am having error here.
}
// End of customer Action.
}
// End of Customer controller.
/*Now Customers.scala model*/
package models
import anorm._
import play.api.db._
import play.api.Play.current
case class Customers(CustomersID: Int, Name: String)
object Customers {
def allCustomers = {
DB.withConnection {implicit connection =>
SQL("Select * from Customers")().map{row =>
Customers(
CustomersID = row[Int]("CustomersID"),
Name = row[String]("Name")
)
// End of Customers object.
}.toList
// SQL ends.
}
// With connection.
}
// End of allCustomers.
}
// End of of Customers.
请注意,我在 conf/application.conf 文件中使用 JDBC 驱动程序进行 mysql 连接
请帮帮我。非常感谢。