Play 2.x @ sign in 路由定义 [英] Play 2.x @ sign in route definitions

查看:106
本文介绍了Play 2.x @ sign in 路由定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Play!框架 (2.3.x).我对路由定义中控制器前面的@"字符的含义感到困惑:

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?

推荐答案

根据 文档:

Play 支持生成两种路由,一种是依赖注入路由器,另一个是静态路由器.默认是静态路由器,但如果您使用播放种子激活器模板,您的项目将包括以下内容build.sbt 中的配置告诉它使用注入的路由器:

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

Play 文档中的代码示例假定您正在使用注入的路由生成器.如果你不使用这个,你可以简单地调整静态路由生成器的代码示例,或者通过在路由的控制器调用部分加上前缀一个 @ 符号,或者通过将每个控制器声明为一个 object而不是 class.

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.

Java 中的等效项是静态与非静态.

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

这篇关于Play 2.x @ sign in 路由定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆