在使用 OR 条件的情况下获取路径的最后一段
Getting the last segment of path in case of using OR condition
我是 spray 框架的新手,我有两条功能相似的路线,只有最后一段发生了变化。我使用“|”运算符将其合并。我怎么知道选择了最后一个片段。
path("users" / Segment / "viewers_count") { userId =>
}
path("users" / Segment / "views_count") { userId =>
}
我使用
组合
path("users" / Segment / ("viewers_count" | "views_count")) { userId =>
//here i want to know if viewers_count OR views_count
// based on that I want to pass "viewers" OR "views" to a module
}
我怎样才能做到这一点。
很简单。您可以将其提取到地图中。
path("users" / Segment / Map("viewers_count" -> "viewers", "views_count" -> "views")) { (userId, selected) =>
// here selected variable will contain viewers or views based on the path.
}
我是 spray 框架的新手,我有两条功能相似的路线,只有最后一段发生了变化。我使用“|”运算符将其合并。我怎么知道选择了最后一个片段。
path("users" / Segment / "viewers_count") { userId =>
}
path("users" / Segment / "views_count") { userId =>
}
我使用
组合path("users" / Segment / ("viewers_count" | "views_count")) { userId =>
//here i want to know if viewers_count OR views_count
// based on that I want to pass "viewers" OR "views" to a module
}
我怎样才能做到这一点。
很简单。您可以将其提取到地图中。
path("users" / Segment / Map("viewers_count" -> "viewers", "views_count" -> "views")) { (userId, selected) =>
// here selected variable will contain viewers or views based on the path.
}