scala - Play 路线文件中的框架错误

标签 scala playframework

我有以下路由接受一组可选参数:

GET  /data  com.controllers.MyController.data(ids: Option[Seq[Long]])

当我编译项目时,出现以下错误:

[warn]  ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[error] (compile:managedSources) @6plhijkoi: Compilation error in /Users/joe/projects/my-project/conf/routes:26
[error] Total time: 5 s, completed Apr 12, 2016 12:03:55 PM

我的路线文件中的第 26 行正是我在上面发布的内容。关于为什么会发生此错误的任何想法?不可能有一个可选的参数序列吗?目标是为以下内容提供一条路线:

localhost:9000/data           - should fetch all the data
localhost:9000/data?id=1&id=2 - should fetch data with id 1 and 2
localhost:9000/data?id=1      - should fetch data with id 1

有什么建议吗?

最佳答案

我弄清楚了问题所在,下面是我如何让它工作的:

GET  /data  com.controllers.MyController.data(ids: List[Long])

注意数据类型,我将类型从 Seq 更改为 List,并且不需要选项。所以电话会变成:

/data?ids=1&ids=2 - filters based on id 1 and 2
/data             - gets me all the data 

关于scala - Play 路线文件中的框架错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36570109/

相关文章:

scala - 如何使用 scala sbt 构建多个 jar 文件

scala - 在scala varargs中强制单个参数

Scala Akka Play, future 不会回来

java - 包含独立主应用程序的 Playframework 应用程序

linux - 在 Scala 中 SBT 被杀死后,不要杀死子进程吗?

scala - 在 PairRDDFunctions.reduceByKey() 中使用 'case'

scala - 如何在 Scala 中使代码线程安全?

mysql - Slick 2 中的多个 PostgreSQL 数据库(同一服务器)访问

app.conf 中的 playframework prod、qa、dev 变量在 Debug模式下不起作用

scala - 为什么 currying 和 uncurrying 不隐含在 scala 中