如果数据库没有结果,如何设置默认Seq[Seo]
?
case class Seo( page: String, title: String, desc: String)
object Seo {
val pageseo = {
get[String]("seo.page") ~
get[String]("seo.title") ~
get[String]("seo.desc") map {
case page~title~desc => Seo (page, title, desc)
}
}
def getSeo(page : String) : Seq[Seo] = {
DB.withConnection { implicit connection =>
SQL("select * from seo where page = {page}").on('page -> page).as(Seo.pageseo *)
}
}
}
答案 0 :(得分:1)
我从Play邮件列表中复制我们的解决方案;)
def getSeo(page: String): Seq[Seo] = {
DB.withConnection { implicit connection =>
SQL("select * from seo where page = {page}").on('page -> page).as(Seo.pageseo *)
} match {
case Nil => Seq(Seo("London", "hello", "o"))
case result => result
}
}