简体   繁体   English

玩框架路线

[英]Play framework routes

I want to catch all unkown GET operations. 我想抓住所有未知的GET操作。

My routes file looks like this: 我的路线文件如下所示:

GET     /                       controllers.MainController.index()
#All other routes

#finally
GET     /[^/]+/                 controllers.MainController.fault()

The final GET definition is at the bottom on the list because of the priority given to the above get operations, otherwise all requests would be true to the /[^/]+/ condition. 最终的GET定义位于列表的底部,因为上面的get操作具有优先级,否则所有请求都将为/ [^ /] + / condition。

The problem is that it goes to the default catch page saying 'Action not found' 问题是它进入默认捕获页面,说“未找到操作”

How can I catch all routes? 我怎样才能赶上所有路线?

I believe 我相信

GET  /*route controllers.MainController.fault()

would work better. 会更好。 route will capture the path that was received, you can pass it as an argument to your fault method. route将捕获已接收的路径,您可以将其作为参数传递给您的fault方法。

But, I would suggest another alternative: you can implement a GlobalSettings object where you override the method 但是,我建议另一种方法:你可以实现一个覆盖方法的GlobalSettings对象

def onHandlerNotFound(request: RequestHeader): Future[SimpleResult]

This method will be called each time you get a request for which it was not possible to find a proper handler. 每次收到无法找到合适处理程序的请求时,都会调用此方法。 You can find more information here: http://www.playframework.com/documentation/2.2.x/ScalaGlobal 您可以在此处找到更多信息: http//www.playframework.com/documentation/2.2.x/ScalaGlobal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM