0

我有这样的功能:

def getList(gig: Gig, createdBy: User = null, all: Boolean = true): List[Bid] = {
    var bys = List[QueryParam](By(Bid.gig, gig))
    if (createdBy!=null) bys = By(Bid.createdBy, createdBy) :: bys
    if (!all) bys = By(Bid.deleted, false) :: bys

    Bid.findAll(bys) //gives error as do not accept List[QueryParam]
  }

如何为 findAll 提供动态数量的 QueryParam?

4

1 回答 1

0

像这样:

Bid.findAll(bys:_*)

旁注:值得避免null赞成 or Option

def getList(gig: Gig, createdBy: Option[User] = None, all: Boolean = true): List[Bid] = {

然后你可以做

val bys = (if (!all) Some(By(Bid.deleted, false)) else None) ++
          (createdBy.map(u => By(Bid.createdBy, u))) ++ 
          List[QueryParam](By(Bid.gig, gig))
Bid.findAll(bys:_*)
于 2013-01-25T10:52:04.903 回答