【问题标题】:Where is "?" placeholder of sql in play2's anorm哪里 ”?” play2 异常中 sql 的占位符
【发布时间】:2012-02-18 08:53:15
【问题描述】:

我们可以在play2的异常中编写如下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)
}

这种格式有时非常有用。

【问题讨论】:

  • 与命名参数相比,使用? 有什么优势?
  • 有时候用?就够清楚了,我们可以少打字
  • 少写多读

标签: placeholder playframework-2.0 anorm


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 2011-04-11
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2018-06-13
    • 2011-03-07
    相关资源
    最近更新 更多