我最近开始学习Scala和Play Framework,当我浏览Anorm documention for the Play Framework时,我看到了以下代码片段:
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
并且遇到了编译错误:
对重载定义的模糊引用, 对象SqlParser中的方法str类型(columnPosition:Int)(隐式c:anorm.Column [String])anorm.RowParser [String] 和对象SqlParser中的方法str类型(columnName:String)(隐式c:anorm.Column [String])anorm.RowParser [String] 匹配预期类型?
我正在使用带有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"
)
有什么问题?
答案 0 :(得分:0)
您错过了v_cur_stg:=x.xmldata.extract('//Fc_curstage/text()').getStringVal();
,必须使用列位置或列名调用它,以便将所引用的列解析为字符串。