scalatra squeryl select参数类型缺失的地方

时间:2013-09-18 10:19:49

标签: scalatra squeryl

我是Scalatra初学者,我有以下路线:

  get("/todos") {
    contentType = formats("json")

    val userid : Int = params.getOrElse("userid", halt(400)).toInt
    val limit : Int = params.getOrElse("limit", "0").toInt
    val offset : Int = params.getOrElse("offset", "0").toInt

    if(limit != 0 && offset != 0) 
        from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo)).toList
    else {
        from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo) orderBy(todo.modified)).page(offset, limit).toList
    }
  }

我无法编译它,我收到以下错误消息:

[info] Compiling 1 Scala source to /home/coelho/www/p.zomg.hu/gfmwa-todo-app/target/scala-2.10/classes...
[error] /home/coelho/www/app/src/main/scala/hu/gfmwa/todoapp/TodoScalatraServlet.scala:25: missing parameter type
[error]         from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo)).toList
[error]                                          ^
[error] /home/coelho/www/app/src/main/scala/hu/gfmwa/todoapp/TodoScalatraServlet.scala:27: missing parameter type
[error]         from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo) orderBy(todo.modified)).page(offset, limit).toList
[error]                                          ^
[error] two errors found
[error] (compile:compile) Compilation failed

我从这里开始学习:http://squeryl.org/selects.html和此处:http://squeryl.org/pagination.html

我在这些页面上看不到参数类型信息,我无法弄清楚,可能是什么问题。我做错了什么?

1 个答案:

答案 0 :(得分:2)

where不期望内部函数(todo=>),而只是一个布尔函数。因此,为了使您的代码有效,请编写类似from(TodoDb.todos)(todo => where(todo.userid === userid) select的内容。

BTW,我建议在看到(todo => where (todo =>(双“todo”定义)等代码片段时要立即谨慎。