问题描述
在这种情况下,谁能告诉我原因
Can anyone tell me why in this case:
Query(Users) foreach {case (userId, userName) =>
println(userId + ", " + userName) }
Scala可以识别userId,但在这种情况下:
Scala recognizes userId, but in this case:
val l = List[(Int, String)]()
Query(Users) foreach {
case (userId, userName) =>
l::(foo(List[(userId, userName)]))
}
不是吗? (例如,在第二种情况下会识别"=>"右侧的userId,但在第一种情况下不会识别)
it doesnt? (as in, the userId on the right of the "=>" is recognized in the second case but not the first)
Users是一个光滑安装的数据库,如下所示:
Users is a slick-mounted database that looks like this:
object Users extends Table[(Int, String)]("Users") {
def userId = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
def userName = column[String]("UserName")
def * = userId ~ userName
}
推荐答案
我认为您的意思是:
l::(foo(List((userId, userName))))
将东西放在方括号之间时,您正在尝试键入列表,我假设您实际上是想将userId
和userName
的Tuple
添加到列表中.
When you put stuff between the square brackets, you are attempting to type the list and I assume you actually wanted to add the Tuple
of userId
and userName
to a List instead.
如果您只想将所有内容放入该List
中,而又不需要该Tuple
提取器,则也可以这样编写:
You could also write it like this if all you wanted to do was put it into that List
and you did not need that Tuple
extractor:
Query(Users) foreach { tup =>
l::(foo(List(tup)))
}
这篇关于光滑的表查询:无法识别值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!