如何不 URL 编码路由参数?
How to not URL encode a route parameter?
我在 Java 上使用 Play 2.4,我有这条路线:
GET /page/:slug controllers.Application.page(slug: String)
因此,例如,如果 slug = this-is-a-slug
,没问题,路线如下所示:
/page/this-is-a-slug
但是,如果 slug = first-part-of-the-slug/second-part-of-the-slug
,URL 栏显示:
/page/first-part-of-the-slug%2Fsecond-part-of-the-slug
我想避免对 slug 进行编码,知道 slug 的数量 'parts' 是未定义的,并将 slug 保留为唯一参数。
我该怎么做?任何帮助表示赞赏。
您需要使用“*”,例如:
/page/*slug
在文档 https://www.playframework.com/documentation/2.4.x/JavaRouting
中查找“Dynamic partspanning several /”部分
If you want a dynamic part to capture more than one URI path segment,
separated by forward slashes, you can define a dynamic part using the
* id syntax, which uses the .* regular expression:
GET /files/*name controllers.Application.download(name)
Here, for a request like GET /files/images/logo.png
, the name
dynamic
part will capture the images/logo.png
value.
我在 Java 上使用 Play 2.4,我有这条路线:
GET /page/:slug controllers.Application.page(slug: String)
因此,例如,如果 slug = this-is-a-slug
,没问题,路线如下所示:
/page/this-is-a-slug
但是,如果 slug = first-part-of-the-slug/second-part-of-the-slug
,URL 栏显示:
/page/first-part-of-the-slug%2Fsecond-part-of-the-slug
我想避免对 slug 进行编码,知道 slug 的数量 'parts' 是未定义的,并将 slug 保留为唯一参数。
我该怎么做?任何帮助表示赞赏。
您需要使用“*”,例如:
/page/*slug
在文档 https://www.playframework.com/documentation/2.4.x/JavaRouting
中查找“Dynamic partspanning several /”部分If you want a dynamic part to capture more than one URI path segment, separated by forward slashes, you can define a dynamic part using the * id syntax, which uses the .* regular expression:
GET /files/*name controllers.Application.download(name)
Here, for a request like
GET /files/images/logo.png
, thename
dynamic part will capture theimages/logo.png
value.