为什么,使用以下代码Scala返回value sql is not a member of StringContext
?
我在Play Framework中使用Slick。
val db = Database.forConfig("db")
val query = sql"""select ID from TEACHER""".as[String]
val people = db.withSession{ implicit session =>
Ok(query.list)
答案 0 :(得分:1)
您可以使用库com.typesafe.play:play-slick_2.11:2.0.0中的导入import driver.api._
。这应该有效:
import driver.api._
val db = Database.forConfig("db")
val query = sql"""select ID from TEACHER""".as[String]
val people = db.withSession{ implicit session =>
Ok(query.list)
答案 1 :(得分:0)
正如上面的评论中提到的那样," code4j" (但值得单独回答),我使用以下内容:
import anorm.SqlStringInterpolation
注意:这适用于Anorm,独立于Slick。
答案 2 :(得分:-1)
试试这个:
import Q.interpolation
val db = Database.forConfig("db")
val query = sql"""select ID from TEACHER""".as[String]
val people = db.withSession{ implicit session =>
Ok(query.list)