play-framework 2 how to escape colon in routes

2019-07-20 14:00发布

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

GET     /:search                       controllers.SearchController.index()

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

thanks

1条回答
神经病院院长
2楼-- · 2019-07-20 14:10

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.

查看更多
登录 后发表回答