让我试着解释一下:)。在你拥有的地方ResultSet
,你应该有一个你实际将结果集映射到的类型。例如,将保存您的行的元组或案例类。如果是自定义(案例)类,您将必须提供一个implicit
GetResult
描述如何从 jdbc 映射ResultSet
到您的类的内容。to 的参数.list
应该是您希望 Slick 放入准备好的语句的占位符的值,而不是您从 a 中得到的值ResultSet
(假设这就是 rs
代表的意思)。
建议的用途是这样的:
import scala.slick.jdbc.{GetResult, StaticQuery}
import StaticQuery.interpolation
val price = 1000.0
// use tuples
val expensiveDevices: List[Device] =
Q.query[String, (Long,Double,Date)]("select * from DEVICE where PRICE > ?").list( price )
// or a case class (needs implicit GetResult for Device)
case class Device(id: Long,price: Double,acquisition: Date)
implicit val getDeviceResult =
GetResult(r => Device(r.<<, r.<<, r.<<))
val expensiveDevices2: List[Device] =
Q.query[String, Device]("select * from DEVICE where PRICE > ?").list( price )
// or the even nicer interpolation syntax
val expensiveDevices3: List[Device] =
sql"select * from DEVICE where PRICE > $price" .as[Device].list