我已經看到了地球的盡頭,爲這個問題的答案。在光滑的2.0上沒有太多的信息。下面是我的地址模型的代碼,如何在插入之後創建返回id的方法?在滑動2.0中插入後返回AutoInc ID
package models
import play.api.Play.current
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick.DB
object Addresses{
val DB_URL:String = "jdbc:h2:mem:fls-play"
val DB_driver:String = "org.h2.Driver"
class Addresses(tag: Tag) extends Table[(String, String, String, String, String)](tag, "ADDRESSES"){
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def city = column[String]("CITY")
def stateName = column[String]("STATE_NAME")
def street1 = column[String]("STREET1")
def street2 = column[String]("STREET2")
def zip = column[String]("ZIP")
def * = (city, stateName, street1, street2, zip)
}
val addresses = TableQuery[Addresses]
def create(city:String, stateName:String, street1:String, street2:String, zip:String) {
DB.withSession{ implicit session =>
addresses += (city, stateName, street1, street2, zip)
}
}
}
謝謝!
的可能重複[怎麼辦我使用Scala Slick返回一個序列生成的id(http://stackoverflow.com/questions/19877185/how-do-i-return-an-sequence-generation-for-the-id-using-scala-slick ) – joescii
@barnes jd我認爲這個答案涉及浮油1.0。 –
@MartinKolinek啊的確的確很好。 – joescii