3

我们可以在 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}format 作为占位符,并指定一个 map 'id->id。有没有?像我们在 play1 中那样用作占位符?

我希望我可以这样写:

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

这种格式有时非常有用。

4

1 回答 1

3

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

这在未来可能会改变,但现在不可能。

于 2012-02-21T15:35:11.523 回答