【发布时间】:2016-11-23 12:06:19
【问题描述】:
我最近开始学习Scala和Play Framework,在翻Anorm documention for the Play Framework的过程中,得到如下代码sn-p:
import anorm.SqlParser.str
val id: List[String] =
SQL("insert into City(name, country) values ({name}, {country})")
.on('name -> "Cambridge", 'country -> "New Zealand")
.executeInsert(str.+) // insertion returns a list of at least one string keys
遇到编译错误:
对重载定义的模糊引用, 类型为 (columnPosition: Int)(隐式 c: anorm.Column[String])anorm.RowParser[String] 的对象 SqlParser 中的两个方法 str 和类型为 (columnName: String)(implicit c: anorm.Column[String])anorm.RowParser[String] 的对象 SqlParser 中的方法 str 匹配预期类型?
我正在使用带有 PostgreSQL 数据库的常规 Scala Play 种子并修改了 HomeController 索引操作:
package controllers
import play.api.Play.current
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.db.{ Database, NamedDatabase, DB }
import anorm._
import anorm.SqlParser.str
@Singleton
class HomeController @Inject()() extends Controller {
def index = Action {
DB.withConnection { implicit c =>
val id: List[String] =
SQL("insert into City(name, country) values ({name}, {country})")
.on('name -> "Cambridge", 'country -> "New Zealand")
.executeInsert(str.+) // insertion returns a list of at least one string keys
Ok("Result is: " + id)
}
}
}
以下是构建依赖项:
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
"com.typesafe.play" %% "anorm" % "2.5.0",
"org.postgresql" % "postgresql" % "9.3-1102-jdbc41"
)
有什么问题?
【问题讨论】: