Is there default catch all route to new actions in Play 2?

老子叫甜甜 提交于 2019-12-10 02:21:17

问题


In Play 1, new actions you defined had a default route.

*       /{controller}/{action}                  {controller}.{action}

(This appeared by default in new projects)

What is the Play 2/2.1 equivalent? Why doesn't it appear in the default routes file?


回答1:


Actually there is a catch-all route available. According to the routing doc in Play 2.0+ you can use Dynamic parts spanning several / so if you put it as exactly last route of given method it will catch every route that wasn't catch before. You can use this for further processing for an example if you have other 'routes' stored in DataBase.

GET   /*path   controllers.Application.seacrhRouteInDB(path: String)



回答2:


Unfortunately the routes in Play Framework 2 don't have this feature.. However you can create a Global class that extends GlobalSettings and implement the catch all in the onRouteRequest method. Check API or documentation for details.

Note this is only available since 2.1.0.



来源:https://stackoverflow.com/questions/15117944/is-there-default-catch-all-route-to-new-actions-in-play-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!