Play 2.x @ sign in route definitions

瘦欲@ 提交于 2021-02-04 15:54:45

问题


I'm learning the Play! framework (2.3.x). I am confused about the meaning of the '@' character in front of the controller in route definitions like this:

POST   /myresource/:id/custom   @controllers.MyResource.custom(id: Long)

As much as I can infer from the context I've seen this in, it probably has to do with the exact controller implementation (object vs class). Or am I completely wrong in this? I can't find anything in the docs and the code I've seen isn't exactly explanatory. Can anyone explain?


回答1:


According to the documentation:

Play supports generating two types of routers, one is a dependency injected router, the other is a static router. The default is the static router, but if you created a new Play application using the Play seed Activator templates, your project will include the following configuration in build.sbt telling it to use the injected router:

routesGenerator := InjectedRoutesGenerator

The code samples in Play’s documentation assumes that you are using the injected routes generator. If you are not using this, you can trivially adapt the code samples for the static routes generator, either by prefixing the controller invocation part of the route with an @ symbol, or by declaring each of your controllers as an object rather than a class.

The equivalent in Java would be static vs non-static.



来源:https://stackoverflow.com/questions/26124171/play-2-x-sign-in-route-definitions

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