使用 Java Playframework 基于基本路由将所有请求发送到单个控制器

Send all requests to a single controller based on a base route using Java Playframework

使用下面的示例,我希望所有 service 请求(以 app/service 开头的路由)由同一个控制器处理。这可能使用 Java Play?

app/service/one
app/service/two/:param

然后控制器将检查路线的其余部分并相应地处理请求。

编辑 1: objective 是为了确保我不必在每次 routes 类型的新路由时更新 routes 文件=12=]需要补充。所以理想情况下,我在路由文件中只有一个 service 路由来处理以 service.

开头的所有路由

是的,为什么不呢?

app/service/one             controllers.Clients.one()
app/service/two/:param      controllers.Clients.two(param: String)

app/service/one             controllers.Clients.path(path = "one")
app/service/two/:param      controllers.Clients.path(path = "two", param: String)

app/service/:cat             controllers.Clients.path(cat = "one")
app/service/:cat/:param      controllers.Clients.path(cat: String, param: String)

或者...看看吃了https://www.playframework.com/documentation/2.6.x/JavaRouting

编辑 1

类似于:

app/service/*path            controllers.Controller.handle(path)

请阅读此处的详细信息: https://www.playframework.com/documentation/2.6.x/JavaRouting#Dynamic-parts-spanning-several-/

关注

Note that dynamic parts spanning several / are not decoded by the router or encoded by the reverse router. It is your responsibility to validate the raw URI segment as you would for any user input. The reverse router simply does a string concatenation, so you will need to make sure the resulting path is valid, and does not, for example, contain multiple leading slashes or non-ASCII characters.