我正在使用Scala Play!使用Anorm框架将数据模型持久化到数据库。我遵循了示例代码here:
case class Bar(id: Pk[Long], name: String)
object Bar {
val simple = {
get[Pk[Long]]("id") ~
get[String]("name") map {
case id~name => Bar(id, name)
}
}
def findAll(): Seq[Bar] = {
DB.withConnection { implicit connection =>
SQL("select * from bar").as(Bar.simple *)
}
}
def create(bar: Bar): Unit = {
DB.withConnection { implicit connection =>
SQL("insert into bar(name) values ({name})").on(
'name -> bar.name
).executeUpdate()
}
}
}
尝试对其进行扩展,我希望检索刚刚创建的主键并将其存储在case类中。
如何检索主键?
https://stackoverflow.com/questions/9859700
复制相似问题