【问题标题】:scalatra squeryl select where parameter type missingscalatra squeryl 选择缺少参数类型的位置
【发布时间】:2013-09-18 10:19:49
【问题描述】:

我是 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

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

【问题讨论】:

    标签: scalatra squeryl


    【解决方案1】:

    where 不期望内部有一个函数(todo=>),而只是一个布尔值。因此,要使您的代码正常工作,请编写 from(TodoDb.todos)(todo => where(todo.userid === userid) select 之类的内容。

    顺便说一句,我建议在看到像(todo => where (todo => 这样的代码片段时要立即小心(双重“todo”定义)。

    【讨论】:

    • 谢谢,删除第二个待办事项解决了问题。我不知道为什么它在文档中:S
    • @coelho,这是文档中的错字。这可能是因为原始示例类似于:TodoDb.todos.where(todo => todo.userid == userid).page(offset, limit),这也是有效的,但如果您需要连接或其他 SQL 限制,则灵活性较差。
    • @jcern 应该报告给 squeryl 邮件列表,然后,我认为。
    • @coelho 它在哪里?我现在正在搜索,但找不到。显然它不在测试中——它们会失败..
    • @VasyaNovikov 我进行了更改并提交了该文档页面的拉取请求。作为参考,他提到的语法可以在这里找到:squeryl.org/pagination.html
    猜你喜欢
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 2019-11-16
    • 2016-06-13
    • 2021-12-05
    • 2021-12-25
    • 2022-01-11
    相关资源
    最近更新 更多