在where子句中使用光滑2的多个参数。

时间:2021-05-07 11:52:28

So I've been scouring the documentation, but I couldn't find something as simple as this.

我一直在搜索文档,但是我找不到这么简单的东西。

This statement seems to work

这个说法似乎行得通

val row = MyTable.where(_.col1 === "val1").firstOption

But this one doesn't

但这一个没有

val row = MyTable.where(_.col1 === "val1" && _.col2 === "val2").firstOption

How can I use multiple parameters in my where clause?

如何在where子句中使用多个参数?

1 个解决方案

#1


6  

You can use underscore for one parameter only once. This is a shortcut for this:

您只能对一个参数使用下划线一次。这是一条捷径:

val row = MyTable.where(x => x.col1 === "val1").firstOption

So in your case this should work:

所以在你的案例中,这应该起作用:

val row = MyTable.where(value => value.col1 === "val1" && value.col2 === "val2").firstOption

#1


6  

You can use underscore for one parameter only once. This is a shortcut for this:

您只能对一个参数使用下划线一次。这是一条捷径:

val row = MyTable.where(x => x.col1 === "val1").firstOption

So in your case this should work:

所以在你的案例中,这应该起作用:

val row = MyTable.where(value => value.col1 === "val1" && value.col2 === "val2").firstOption