标签:import cal rgs 操作 user app apply() lis operation
Batch 操作
import scalikejdbc._ import scalikejdbc.config._ object BatchOperation { def main(args: Array[String]): Unit = { DBsWithEnv("dev").setupAll() case class User(id: Int, name: String, age: Int) val ls = List[User]( User(5, "aa", 2), User(6, "bb", 8), User(7, "cc", 9)) val lsi = List[User]( User(5, "aau", 2), User(6, "bbu", 8), User(7, "ccu", 9)) val batchInsertParams = for (el <- ls) yield (List(el.id, el.name, el.age)) val batchUpdateParams = for (el <- lsi) yield (List(el.name, el.id)) DB localTx { implicit session => sql"insert into user (id, name, age) values (?, ?, ?)".batch(batchInsertParams: _*).apply() } DB localTx { implicit session => sql"update user set name = ? where id = ?".batch(batchUpdateParams: _*).apply() } DBsWithEnv("dev").closeAll() } }
标签:import cal rgs 操作 user app apply() lis operation
原文地址:http://www.cnblogs.com/AK47Sonic/p/7076211.html