使用Scala和anorm in play将结果集转换为Seq [(String,String)]

时间:2016-01-25 07:27:39

标签: scala playframework anorm

我试图使用anorm从mySQL数据库表中获取结果集。这是我的代码。

.nav {
  background: #00A2E8;
}
.text-center {
  text-align: center;
  padding: 10px;
}
.copright {
  line-height: 40px;
}
.side-image {
  float: right;
  margin-left: -40px;
}

我尝试用一​​些实验改变代码,但没有奏效。

但是我收到了这个错误

  

从stdout读取:   D:\ PROJECTS \ test \ Project_VendorM8 \ app \ models \ Brand.scala:69:type   不匹配;从stdout读取:发现:   scala.collection.immutable.Nil.type从stdout读取:必需:   scala.collection.mutable.Seq [(String,String)]   D:\ PROJECTS \ test \ Project_VendorM8 \ app \ models \ Brand.scala:69:type   不匹配;发现:scala.collection.immutable.Nil.type必需:   scala.collection.mutable.Seq [(String,String)]从stdout读取:   foldLeftSeq [(String,String)] {(cs,c)=>         foldLeftSeq [(String,String)] {(cs,c)=>从stdout读取:^

2 个答案:

答案 0 :(得分:1)

正如评论中所提到的,一个更简单的解决方案不仅仅是使用map并写:

def options: Seq[(String,String)] = DB.withConnection { implicit connection =>
  SQL("select * from m_brand order by brandName").as(simple *)
    .map( b => (b.id.toString, b.name))
    .toSeq
}

答案 1 :(得分:0)

更改

foldLeft[Seq[(String, String)]](Nil)

foldLeft(Seq.empty[(String, String)])