【发布时间】:2014-08-10 18:08:28
【问题描述】:
我正在考虑以下哪种方法更好。 要将会话重用于更大的范围还是使用更小的范围?
下面两个例子来说明区别。
示例 1 小范围:
def thumbnail(id: Int) = SecuredAction { implicit request =>
DB.withSession { implicit session => Models.get(id) } match {
case None => NotFound("The requested model is either not in the db or you lack access to it.")
case Some(model) => {
Ok(views.html.model.thumbnail(model, DB.withSession { implicit session => Tags.tags(model) }))
}
}
}
示例2大范围:
def thumbnail(id: Int) = SecuredAction { implicit request =>
DB.withSession { implicit session =>
Models.get(id) match {
case None => NotFound("The requested model is either not in the db or you lack access to it.")
case Some(model) => {
Ok(views.html.model.thumbnail(model, Tags.tags(model)))
}
}
}
}
你怎么看?
【问题讨论】:
标签: java database scala playframework slick