{"action":"opened","issue":{"url":"https://api.github.com/repos/JavaProgrammerLB/JavaNinja/issues/1","labels_url":"https://api.github.com/repos/JavaProgrammerLB/JavaNinja/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/JavaProgrammerLB/JavaNinja/issues/1/comments","events_url":"https://api.github.com/repos/JavaProgrammerLB/JavaNinja/issues/1/events","html_url":"https://github.com/JavaProgrammerLB/JavaNinja/issues/1","id":90535795,"number":1,"title":"Routing","user":{"login":"JavaProgrammerLB","id":3973419,"avatar_url":"https://avatars.githubusercontent.com/u/3973419?v=3","gravatar_id":"","url":"https://api.github.com/users/JavaProgrammerLB","html_url":"https://github.com/JavaProgrammerLB","followers_url":"https://api.github.com/users/JavaProgrammerLB/followers","following_url":"https://api.github.com/users/JavaProgrammerLB/following{/other_user}","gists_url":"https://api.github.com/users/JavaProgrammerLB/gists{/gist_id}","starred_url":"https://api.github.com/users/JavaProgrammerLB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JavaProgrammerLB/subscriptions","organizations_url":"https://api.github.com/users/JavaProgrammerLB/orgs","repos_url":"https://api.github.com/users/JavaProgrammerLB/repos","events_url":"https://api.github.com/users/JavaProgrammerLB/events{/privacy}","received_events_url":"https://api.github.com/users/JavaProgrammerLB/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-24T01:33:43Z","updated_at":"2015-06-24T01:33:43Z","closed_at":null,"body":">Ninja web framework是一个java web框架，本文档为ninja的文档中文翻译，大家在阅读的过程中如果发现问题，可以给我提出来，我们共同学习ninja web framework框架\r\n\r\nRouting\r\nNinja features one central route file. We think this is important, because you immediately can see what routes your application provides. It especially facilitates designing a nice restful application and Api, because you have a good overview what is going on.\r\n\r\nRouting\r\n\r\nNinja的特性\"一个中央路由文件\"。我们认为这是重要的，这样你马上可以看到你的应用提供了怎样的路由。它特别有利于设计一个优秀的restful应用和API，因为你对于即将发生什么早已经胸有成竹。\r\n\r\nBasics\r\n\r\nThe route file is a plain old java file living at conf/Routes.java.\r\n\r\nRoutes.java implements the interface ApplicationRoutes.java. This interface defines a method called public void init(Router router) {…} which allows us to map incoming requests to controllers and their methods.\r\n\r\nBasics\r\n\r\n路由文件是一个简单原始的Java文件在conf/ routes.java\r\n\r\nRoutes.java实现接口Applicationroutes.java。这个接口定义的方法称为public void init（路由器路由器）{……}这让我们地图的传入请求的控制器及其方法。\r\n\r\npublic class Routes implements ApplicationRoutes {\r\n    @Override\r\n    public void init(Router router) {\r\n        \r\n        // a GET request to \"index\" will be handled by a class called\r\n        // \"AppController\" its method \"index\".\r\n        router.GET().route(\"/index\").with(AppController.class, \"index\");\r\n        ...\r\n \r\n    }\r\n}\r\nThe init(…) method provides us with the Router and router allows us to define what happens for GET, POST, PUT, OPTIONS, HEAD and DELETE requests.\r\n\r\n在Router类中提供了inti(...)方法，router允许我们去定义GET，POST,PUT,OPTIONS,HEAD和DELETE等不同的请求将发生什么。\r\n\r\nAnd if you want to route a http method not yet supported by Ninja out of the box you can always use route.METHOD(“MY_CUSTOM_HTTP_METHOD”).route(…)….\r\n\r\n如果你想路由一个还没有被Ninja支持的http方法，立即可用的是你总是可以使用route.METHOD(\"MY_CUTOM_HTTP_METHOD\").route(...)...\r\n\r\nRoutes are matched top down. If an incoming request potentially maps to two routes, the route defined first is executed.\r\nRoutes将会从上到下配对。如果一个请求潜在的映射到两个路线，会被执行的路线是第一条定义的线路。\r\nWith result directly\r\n\r\n直接给出结果\r\n\r\nYou can use Result object to render a static page simply without controller.\r\n\r\n不使用控制器类，使用Result对象是就可以容易的提供一个静态页面\r\n\r\npublic class Routes implements ApplicationRoutes {\r\n@Overridepublic void init(Router router) {\r\n// a GET request to \"/\" will be redirect to \"/dashboard\"\r\n        router.GET().route(\"/\").with(Results.redirect(\"/dashboard\"));\r\n// show a static page\r\n        router.GET().route(\"/dashboard\").with(Results.html().template(\"/dashboard.html\"));...}\r\n}\r\n\r\nRegex in your routes\r\n\r\n在你的路线中使用正则表达式\r\n\r\nRoutes can contain arbitrary Java regular expressions. You can use these regular expressions simply by putting them into the route definition.\r\n\r\nRoutes可以包含任何的Java正则表达式。要使用那些正则表达式你可以直接把他们放在路线的定义中。\r\n\r\nSome examples:\r\n\r\n下面是一些例子：\r\n\r\n// matches for instance \"/assets/00012\", \"/assets/12334\", ...\r\nrouter.GET().route(\"/assets/\\\\d*\").with(AssetsController.class, \"serveDigits\");\r\n// matches for instance \"/assets/myasset.xml\", \"/assets/boing.txt\", ...\r\nrouter.GET().route(\"/assets/.*\").with(AssetsController.class, \"serveArbitrary\");\r\n// 匹配这样的实例： \"/assets/00012\", \"/assets/12334\", ...\r\nrouter.GET().route(\"/assets/\\\\d*\").with(AssetsController.class, \"serveDigits\");\r\n// 匹配这样的实例： \"/assets/myasset.xml\", \"/assets/boing.txt\", ...\r\nrouter.GET().route(\"/assets/.*\").with(AssetsController.class, \"serveArbitrary\");\r\nIn the first example \\\\d* tells the router to match digits (defined by \\\\d) of arbitrary length (defined by *). In the second example .* lets the router match arbitrary characters (.) of arbitrary length (defined by *).\r\n\r\n在第一个例子当中\\\\d*告诉路由器去匹配任意长度的（通过*定义）的十进制数（通过\\\\d定义）。第二个例子中.*让路由器匹配任意长度的（通过*定义）任意的字符（通过.定义）。\r\n\r\nThis example also shows what happens if two routes match. For instance a request to /assets/00012 is matched by both route definitions. In that case the first matching route from top will be executed. In our case method serveDigits.\r\n\r\n这个例子也给我们展示了如果一个请求同时匹配了两条线路会发生什么。对于请求到/assets/00012的例子，这个请求同时匹配到两条定义的线路。在这个实例中按照从上往下的顺序第一条匹配的路线会被执行，本例中具体被执行的方法是serveDigits.\r\n\r\nMore on regular expressions: \r\n\r\n访问如下的网站了解更多：\r\n\r\nhttp://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\r\n\r\nGetting variable url parts into your controller method\r\n\r\n把可变的url部分放到你的控制器方法中\r\n\r\nA controller usually not only renders stuff, but also takes some inputs and does something with them.\r\n\r\n一个控制器不仅提供一个东西，也可以提供一些输入，用这些输入做些事。\r\n\r\nLet’s assume we got a request like that:\r\n\r\n假设我们得到了一个如下的请求：\r\n\r\nGET /user/12345/my@email.com/userDashboard\r\nLooks like a GET request to the userDashboard. The request seems to contain an id and an email. As application developer you want to have a convenient way to get id and email inside your controller. Ninja allows you to define and name parts of your routes via curly braces {…}:\r\n\r\n这个看起来像是指向userDashboard的GET请求。这个请求似乎包含一个id和一个emaiil。作为一个应用的开发者你想要在你的控制器中有一个方便的方式去获得id和email。Ninja允许你通过大括号定义和命名你的线路。\r\n\r\nrouter.GET().route(\"/user/{id}/{email}/userDashboard\").with(ApplicationController.class, \"userDashboard\");\r\nWe can then inject id and email into our controller via annotation @PathParam.\r\n\r\n在之后我们可以通过@PathParam声明注入id和email到我们的控制器中。\r\n\r\npackage controllers;\r\n@Singletonpublic \r\nclass AppController {\r\npublic Result userDashboard(@PathParam(\"id\") String id,@PathParam(\"email\") String email) {\r\n//do something with the parameters...\r\n }\r\n}\r\nBy default Ninja replaces curly braces with the following regex to match a variable part: ([^/]*). That means that variable parts match arbitrary characters but do not span over any path separators \"/\". If you need more control please you'll find more in the next section.\r\n默认的Ninja不使用大括号你可以使用如下的正则表达式来匹配一个可变的部分：([^/]*)。这意味着可变的部分匹配任意字符但是不从任何的路径分隔符\"/\"跨越。如果你需要更多的控制敬请期待下一部分。\r\nRegular expressions in variable route parts\r\n\r\n在可变的线路部分使用正则表达式\r\n\r\nNinja allows you to specify regular expressions that will be used to match arbitrary parts of your url.\r\n\r\nNinja允许你详述将被使用到匹配你的url中的任意部分的正则表达式。\r\n\r\nThe syntax is {PRAMETER_NAME: REGEX} (with a whitespace after the “:”).\r\n\r\n语法是{PARAMETER_NAME: REGEX}(在冒号后面有一个空格)\r\n\r\nFor instance a route like /assets/{fileName: .*} will match everything after /assets/. Imagine a request to /assets/css/app.css. This request will be handled by the route and accessing the path parameter fileName will return css/app.css.\r\n\r\n实现一个像 /assets/{fileName: .*}这样的路线会匹配满足 /assets/.的一切。想象有一个指向/assets/css/app.css的请求。这个请求会被这条路线处理而且会连接路径参数文件会返回css/app.css。\r\n\r\nRoutes can contain multiple variable parts with regular expressions.\r\n\r\nRoutes中可以包含多个由正则表达组成的可变部分。\r\n\r\nFor example, for a request to /categories/1234/products/5678, where category is expected to be an integer value and product to be either integer or string value, you can define routes like that:\r\n\r\n例如，对于到/catagories/1234/products/5678的请求，其中category需要一个int值，product可以是int或是String型数据，你可以定义如下的路线：\r\n\r\nrouter.GET().route(\"/categories/{catId: [0-9]+}/products/{productId: [0-9]+}\").with(ProductController.class, \"product\");\r\nrouter.GET().route(\"/categories/{catId: [0-9]+}/products/{productName: .*}\").with(ProductController.class, \"productByName\");\r\nThe request above will be handled by first route, and request to /categories/1234/products/mouse will be handled by second route.\r\n\r\n上面说到的请求会被第一条线路处理，到/categories/1234/products/mouse的请求则会被第二条线路处理。\r\n\r\nValues of variable parts of a route are injected into our controller (explained above) and are implicitly validated with regular expressions. So our controller for routes above would be like that (look at @PathParam argument types):\r\n\r\n可变部分的值被注入到我们的控制器（在上面解释过）而且连带着讲了正则表达式。因此上面对于路线的控制会像这样（注意看@PathParam参数的类型）：\r\n\r\npackage controllers;\r\n@Singletonpublic class ProductController {\r\npublic Result product(@PathParam(\"catId\") int catId,@PathParam(\"productId\") int productId) {\r\n// find product by id in given category \r\n}\r\npublic Result productByName(@PathParam(\"catId\") int catId,@PathParam(\"productName\") String productName) {\r\n// find product(s) by name in given category \r\n }\r\n}\r\nNote at how regular expressions in routes can be used to validate path parameters and to define fine grained routing.\r\n\r\n注意其中正则表达式是怎么被使用到去验证路径参数和定义好清晰的路由。\r\n\r\nYou can use any Java compliant regular expressions for matching. Please refer to the official documentation at http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html.\r\n\r\n你可以使用任何你顺手的正则表达式来进行匹配。想了解正则表达式的官方文档查看如下链接：\r\n\r\nhttp://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html.\r\n\r\nInjecting objects into the Router\r\n\r\n注入对象到Router\r\n\r\nBecause the Route.java is just a plain old java file we can also inject arbitrary stuff into it (via Guice).\r\n\r\n因为Route是相对古老的java文件，我们也可以注入进去任意的东西（通过Guice）\r\n\r\nA popular use case is to inject ninjaProperties. This allows us to activate / deactivate certain routes based on the environment we are in.\r\n\r\n一个常见的使用案例是注入ninjaProperties。这允许我们去激活/不激活特定的路线根据我们所在的环境。\r\n\r\nThe following example shows that a setup route is not available when running in production:\r\n\r\n接下来的例子展示了在产品运行中一个设置为不可用的路线：\r\n\r\npublic class Routes implements ApplicationRoutes {\r\n@InjectNinjaProperties ninjaProperties;\r\n@Override\r\npublic void init(Router router) {\r\n// a GET request to \"index\" will be handled by a class called\r\n// \"AppController\" its method \"index\".router.GET().route(\"/index\").with(AppController.class, \"index\");\r\n...\r\n// only active when not in production mode:if (!ninjaProperties.isProd) {\r\n            router.GET().route(\"/setup\").with(AppController.class, \"setup\");\r\n  }\r\n }\r\n}\r\nReverse routing\r\n\r\n路由反转\r\n\r\nLet’s say you want to know the final route of a class ApplicationController.class, method “index”. Assume that the original raw route looked like a simple “/”.\r\n\r\nYou can get the final url by injecting the router into your controller and then calling getReverseRoute\r\n\r\n让我们看到你想知道一个类ApplicationController.class，“index”方法最终的路线。假设原始的路线看起来像一个简单的\"/\"。你可以通过把路线注入到你的控制器中获得最终的url，然后调用getReverseRoute\r\n\r\n@InjectRouter router;\r\n...\r\npublic void myMethod() {\r\n// will result into \"/\"String generatedReverseRoute  = router.getReverseRoute(ApplicationController.class, \"index\");\r\n...\r\n}    Now consider a more complex example. Say the original raw route contained placeholders on the following form: /user/{id}/{email}/userDashboard. You can now ask the router for the final url, but you must provide a map containing mappings from placeholders to final values. If the key cannot be found as placeholders their value will be added as query parameters:\r\n现在我们来考虑一个更复杂的例子。接下来看以这种形式包含占位符的原始路由：/user/ {id} /{email}/ userdashboard 。你现在可以让Router对象给你最后的url，但是你必须提供一个包含从占位符映射到最终值得map。如果不能找到替代占位符的key，占位符的值将被添加做查询参数。\r\n\r\n@InjectRouter router;...public void myMethod() {\r\n\r\n    map = Maps.newHashMap();\r\n    map.put(\"id\",\"myId\");\r\n    map.put(\"email\",\"myEmail\");\r\n    map.put(\"paging_size\",\"100\");\r\n    map.put(\"page\",\"1\");// this will result into \"/user/myId/myEmail/userDashboard?paging_size=100&page=1\"String generatedReverseRoute \r\n        = router.getReverseRoute(ApplicationController.class,\"userDashboard\", \r\n            map);...}      \r\nA note on encoding / decoding\r\n\r\n在编码/解码的一个note\r\n\r\nEncoding / Decoding of Urls is not as easy as you think it is. Ninja tries to simplify everything as much as possible, but as user of the Api you have to know what you are submitting to Ninja.\r\n\r\nUrl的编码/解码不是你想象中的那么容易。Ninja试图尽可能的简化一切，但是作为ninja API的用户你必须清楚你提交的内容。\r\n\r\nWe recommend the following excellent article from Lunatech before you use encoding / decoding actively in your application.\r\n\r\n在你的应用程序使用编码/解码之前，我们推荐阅读这篇来自Lunatech的优秀文章。\r\n\r\nLet’s reconsider the controller method from above:\r\n\r\n让我们重新考虑上面的控制器方法：\r\n\r\npackage controllers;\r\n@Singleton\r\npublic class ApplicationController {\r\npublic Result index(@PathParam(\"id\") String id,@PathParam(\"email\") String email,@Param(\"debug\") String debug) {\r\n//使用参数……\r\n }\r\n}\r\nYou can expect that String id and String debug are both correctly decoded values. BUT This assumes that you are encoding the values correctly on the client side. And encoding is different for query parameters or stuff in the path. Do not even think about using URLEncoder for encoding urls. This is wrong.\r\n\r\n你可以期望字符串id 和字符串debug都正确解码值。但这里的前提是你在客户端正确的编码了传递的值。编码是不同于查询参数或路径下的其他事情。甚至不要考虑用URLEncoder来编码url。这是错误的。\r\n\r\nSimple example that outlines some of the difficulties: Think of a route “/user/{id}/userDashboard”.\r\n\r\n接下来看一些和大多数的例子有一些不同的例子：考虑这样一个路由：\"/user/{id}/userDashboard\".\r\n\r\nLet’s say your id is “rootuser/domain”. If you do not encode the slash in the middle you end up with a url like /user/rootuser/domain/userDashboard. And the this url does not match the route because of the “/”.\r\n\r\n假如说你的id 是“rootuser /domain”。如不你不解码中间的斜线，你将会得到一个这样的url：/user/rootuser/domain/userDashboard。但是这个url不能匹配路由对象因为“/”。\r\n\r\nTherefore you have to encode your id correctly. In that case it would be: rootuser%2Fdomain. When the user then visits /user/rootuser%2Fdomain/userDashboard the route matches and a @PathParam(“id”) would then be rootuser/domain as it is decoded by Ninja.\r\n\r\n因此你不得不正确的解码你的id。在这种情况应该使用：rootuser%2Fdomain。当用户访问/user/ rootuser%2Fdomain/ userdashboard时路由成功匹配而且通过Ninja一个@ pathparam（“id”）将被作为rootuser /domain的解码。\r\n\r\nIn principle it is really simple. But it is even simpler to mess encoding / decoding up. The article from Lunatech mentioned earlier is awesome and explains everything.\r\n\r\n原则上它真的很简单。但是解码/编码也是特别容易弄混。从Lunatech前面的文章提到了而且解释了一切。\r\n\r\nJAX-RS-style Annotated Routes in Ninja (optional)\r\n\r\n在Ninja中JAX-RS-style类型注解（可选）\r\nNinja-jaxy-routes allows you to register your routes using annotations similar to JAX-RS.\r\n\r\nNinja-jaxy-routes允许你使用类似JAX-RS的方式注解的使用去注册你的路由。\r\n\r\nYou may use the standard Ninja route registration in combination with this route builder or you may replace all your route registrations with annotations.\r\n\r\n你可以使用标准Ninja路由注册方式结合这种路由建造模式或者你可以使用声明替换你所有的路由注册方式。\r\n\r\nNOTE: Your annotated controllers must be located somewhere within your application’s configured controller package or a subpackage thereof.\r\n\r\n注意：你声明的控制器必须放在你应用配置控制控制器的包或应用配置控制器的子包里。\r\n\r\nAdd the ninja-jaxy-routes dependency\r\n\r\n在maven配置中增加ninja-jaxy-routes 依赖\r\n<dependency>\r\n    <groupId>org.ninjaframework</groupId>\r\n    <artifactId>ninja-jaxy-routes</artifactId>\r\n    <version>${ninja.version}</version>\r\n</dependency>\r\n<dependency>\r\n    <groupId>org.ninjaframework</groupId>\r\n    <artifactId>ninja-jaxy-routes</artifactId>\r\n    <version>${ninja.version}</version>\r\n</dependency>\r\nInitialize JaxyRoutes in your conf.Routes class.\r\n\r\n在你的conf路由类中初始化JaxyRoutes。\r\n@Inject\r\nJaxyRoutes jaxyRoutes;\r\n@Override\r\npublic void init(Router router) {\r\n    jaxyRoutes.init(router);\r\n}\r\n@Inject\r\nJaxyRoutes jaxyRoutes;\r\n\r\n@Override\r\npublic void init(Router router) {\r\n\r\n    jaxyRoutes.init(router);\r\n\r\n}\r\nAnnotate Your Controllers\r\n\r\n对你的控制器进行注解\r\nNow you are ready to start annotating your controllers.\r\n\r\n现在你已经准备好注解你的控制器了。\r\n\r\nPaths\r\n\r\n路径\r\nNinja-jaxy-routes supports multiple @Path specs per controller method and also supports controller class inheritance.\r\n\r\nNinja-jaxy-routes支持多个@path规范每一个控制器方法，而且支持控制器类的继承。\r\n\r\nThe following example will register two GET routes /base/middle/app/get and /base/middle/app/retrieve for the same controller method.\r\n\r\n接下来的例子将对于同一个控制器方法注册两个GET路由：/base/middle/app/get和/base/middle/app/retrieve.\r\n\r\n@Path(\"/base\")\r\nclass Base {\r\n}\r\n@Path(\"/middle\")\r\nclass Middle extends Base {\r\n}\r\n@Path(\"/app\")\r\nclass App extends Middle {\r\n    @Path({\"/get\", \"/retrieve\"})\r\n    @GET\r\n    Result get() {\r\n        return Results.text().renderRaw(\"Yahoo!\"); \r\n    }        \r\n}\r\n@Path(\"/base\")\r\nclass Base {\r\n}\r\n\r\n@Path(\"/middle\")\r\nclass Middle extends Base {\r\n}\r\n\r\n@Path(\"/app\")\r\nclass App extends Middle {\r\n\r\n    @Path({\"/get\", \"/retrieve\"})\r\n    @GET\r\n    Result get() {\r\n        return Results.text().renderRaw(\"Yahoo!\"); \r\n    }        \r\n}\r\nIf the Base and Middle parent classes had each specified multiple paths, all permutations of the complete routes would be registered too.\r\n\r\n如果Base和Middle的父类每个都指定多个路劲，所有的完成的路由的排列分布都会被注册。\r\n\r\nHttp Methods\r\n\r\nHttp方法\r\nBy default, all routes are assumed to be GET routes unless they are specifically annotated.\r\n\r\n默认情况下，所有的路由假设为GET 路由除非它们有特别的注解。\r\n\r\nThe following common HTTP method annotations are available:\r\n\r\n如下的普通HTTP方法注解是可用的：\r\n\r\n@DELETE\r\n@GET\r\n@HEAD\r\n@OPTIONS\r\n@PATCH\r\n@POST\r\n@PUT\r\n@DELETE\r\n@GET\r\n@HEAD\r\n@OPTIONS\r\n@PATCH\r\n@POST\r\n@PUT\r\nIf the built-in methods are insufficient, you may implement your own custom HTTP methods:\r\n\r\n如果内嵌的方法不够充足，你可以实现你自定义的HTTP方法：\r\n\r\n@Target(ElementType.METHOD)\r\n@Retention(RetentionPolicy.RUNTIME)\r\n@HttpMethod(\"CUSTOM\")\r\npublic @interface CUSTOM {\r\n}\r\n@Target(ElementType.METHOD)\r\n@Retention(RetentionPolicy.RUNTIME)\r\n@HttpMethod(\"CUSTOM\")\r\npublic @interface CUSTOM {\r\n}\r\nRegistration Order\r\n\r\n注册顺序\r\nSince your controllers and methods are reflectively loaded we can not expect a predictable route registration order from the JVM.\r\n\r\n尽管你的控制器和方法是放射加载的，但是我们不能通过java虚拟机预测路由注册顺序。\r\n\r\nTo compensate for this, you may specify the @Order annotation on a controller method to dictate the ordering of routes.\r\n\r\n为了补偿这一点，你可以在一个控制器方法指定@Order声明来规定路由的顺序。\r\n\r\nIt is not necessary to specify an @Order for every method.\r\nLower numbers are registered first, higher numbers later.\r\nIf two methods have the same order, the registration order is determined by String comparison of the complete method address (controller+method).\r\n1.不是每个方法都必须指定一个@Order声明。\r\n\r\n2.数字小的先注册，数字大的在后面注册。\r\n\r\n3.如果两个方法有同样的顺序，注册顺序由完成的方法地址（控制器+方法）的String值来进行比较。\r\n\r\nHere is an example of specifying an @Order.\r\n\r\n下面是一个指定@Order注解的例子。\r\n\r\n@Path({\"/get\", \"/retrieve\"})\r\n@GET\r\n@Order(10)\r\nResult something() {\r\n}\r\n@Path({\"/get\", \"/retrieve\"})\r\n@GET\r\n@Order(10)\r\nResult something() {\r\n}\r\nRuntime Mode Inclusions/Exclusions\r\n\r\n运行时模式包含/不包含\r\nYou may include/exclude routes based on the Ninja runtime mode.\r\n\r\n根据Ninja的运行时模式你可以包括/排除路由。\r\n\r\nIf no mode annotations are specified, then the route is available in all modes.\r\n\r\nYou may specify multiple mode annotations on a controller method.\r\n\r\n@Dev\r\n\r\n@Prod\r\n\r\n@Test\r\n\r\n1.如果没有指定任何的模式注解，这个路线在所有的模式中都可用、\r\n\r\n2.你可以在一个控制器方法中指定多个模式声明\r\n\r\n3.@DEV\r\n\r\n4.@Prod\r\n\r\n5.@Test\r\n\r\nHere is an example of specifying @Dev and @Test.\r\n\r\n这是一个指定@Dev和@Test的例子。\r\n\r\n@Path(\"/diagnostics\")\r\n@GET\r\n@Dev @Test\r\nResult diagnostics() {\r\n}\r\n@Path(\"/diagnostics\")\r\n@GET\r\n@Dev @Test\r\nResult diagnostics() {\r\n}\r\nNinjaProperties Inclusions/Exclusions\r\n\r\nNinja参数包含与排除\r\nIt is also possible to include/exclude a route based on a NinjaProperties key.\r\n\r\nIf the key does not exist in your runtime config, the route is not registered.\r\n\r\n通过一个Ninja参数key包含或者排除一个路由也是可能的。\r\n\r\n如果这个key不存在于你的运行时配置，这个路由不会被注册。\r\n\r\n@Path(\"/sneaky\")\r\n@GET\r\n@Requires(\"sneaky.key\")\r\nResult somethingSneaky() {\r\n}\r\n@Path(\"/sneaky\")\r\n@GET\r\n@Requires(\"sneaky.key\")\r\nResult somethingSneaky() {\r\n}"}}