哪里 ”?” play2的anorm中sql的占位符

时间:2012-02-18 08:53:16

标签: placeholder playframework-2.0 anorm

我们可以在play2的anorm中写下sql,如下所示:

def findById(id: String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id={id}").on('id -> id).as(simple.singleOpt)
}

它使用{xxx}格式作为占位符,并指定地图'id->id。反正有没有像我们在play1中那样使用?作为占位符?

我希望我可以这样写:

def findById(id:String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id=?").on(id).as(simple.singleOpt)
}

此格式有时非常有用。

1 个答案:

答案 0 :(得分:3)

不,目前Anorm使用Scala符号进行映射,您不能使用'?'。

这可能会在未来发生变化,但目前还不可能。