播放框架2如何在路线中逃脱冒号 [英] play-framework 2 how to escape colon in routes

查看:58
本文介绍了播放框架2如何在路线中逃脱冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的play2路由文件中,我尝试使用冒号作为文字:

in my play2 routes file, I am trying to use a colon as a literal:

GET     /:search                       controllers.SearchController.index()

,但play抱怨缺少一个参数.我该如何逃避结肠(我尝试过反斜杠)?

but play complains, that a parameter is missing. How do I escape the colon (I tried backslashing it)?

谢谢

推荐答案

您必须引入一个虚拟regex参数,例如:

You must introduce a dummy regex parameter, as such:

GET     /$colon<\:>search           controllers.SearchController.index(colon)

然后,您还必须重新定义控制器方法:

You must then also redefine your controller method:

public static Result index(String colon) {
 ....

解析器的构建方式使得除此方法外,路径表达式不能被转义.

The parser is built in such a way that path expressions cannot be escaped, save for this method.

这篇关于播放框架2如何在路线中逃脱冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆