斯卡拉lift:使用 LiftRules.statelessRewrite.append 外部声明的变量重写 URL
我正在寻找一种使用在 LiftRules.statelessRewrite.append
范围之外声明的列表来重写 lift 中的 URL 的解决方案,
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath("abc" :: Nil, _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil)
}
以下代码的工作方式与上面的代码相同:
val requestList = "abc" :: Nil
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath(requestList, _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil)
}
我希望 有人写过如何使用 lift 2.0 获得这样的功能吗?
[编辑]
您能否建议以参数形式访问此列表后缀的最佳方法。我想要得到的是类似于:
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath(`requestList` ::: List(someId), _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil, Map("someId" -> someId))
}
I'm looking for a solution for rewriting URLs in lift using a list declared outside the scope of LiftRules.statelessRewrite.append
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath("abc" :: Nil, _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil)
}
I'd like to have the following code working the same as the one above:
val requestList = "abc" :: Nil
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath(requestList, _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil)
}
Could anyone write how to get such functionality with lift 2.0?
[edit]
Could you also suggest the best way to access this list's suffix as parameter. What I would like to get is similar to:
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath(`requestList` ::: List(someId), _ , _ , _ ), _ , _ ) =>
RewriteResponse("index" :: Nil, Map("someId" -> someId))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
case
语句中的任何小写变量都将创建一个具有该名称的新变量,因此requestList
将被隐藏。试试这个:另一种方法是使用反引号(Scala ref:“稳定标识符模式”):
在您的情况下,第二种形式将是选择的规范形式,但一般来说第一种形式会更强大。
作为第三种选择,您还可以定义
val RequestList = requestList
并与大写版本进行匹配,但我建议不要这样做,除非您有充分的理由创建大写的RequestList
。Any lowercased variable in a
case
statement will create a new variable with that name, thereforerequestList
is going to be shadowed. Try this:Another approach would be to use backticks (Scala ref: ‘stable identifier patterns’):
In your case, the second form would be the canonical one to choose, but in general the first form will be more powerful.
As a third alternative, you could also define
val RequestList = requestList
and match against the uppercased version, though I would advise against this unless you have a good reason for creating a capitalisedRequestList
.