使用Scala在Play Framework中进行路由的最佳做法是哪种方法? [英] which way is a better practice for routing in Play Framework with Scala?

查看:104
本文介绍了使用Scala在Play Framework中进行路由的最佳做法是哪种方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://github.com/playframework/play-samples/blob/2.8.x/play-scala-starter-example/conf/routes

https ://github.com/playframework/play-samples/blob/2.8.x/play-scala-rest-api-example/conf/routes

我在Play中看到有3种指定路线的方法,如上所示,哪种方法被认为是推荐的?哪种文件夹结构更好?

I see in Play there are 3 ways to specify routes, as shown above, which way is considered the recommended one? Which folder structure is better?

推荐答案

您的第一个代码示例使用 SIRD 路由器,而第二个示例使用从路由文件生成的路由器.

Your first code example uses a SIRD router, whereas the second example uses a generated router from a routes file.

第三个示例仅使用一个路由文件,该文件生成一个路由器,该路由器将控制权传递给另一个路由器以使用特定的前缀-无论是生成还是手工编码的.因此,这与第二个示例没有什么不同.

The third example just uses a routes file which generates a router that passes control to another router for a specific prefix -- no matter whether this was generated or hand-coded. So, this is no different than the second example.

一个没有明显的优势.使用路由文件通常更简洁,更容易",但是使用DSL将路由绑定到某些操作时,您将拥有更多的控制权.

There is no clear advantage of one over the other. Using a routes files is usually more succinct and "easier", but you have more control when using the DSL to bind your routes to some actions.

文件夹的结构也只是一个问题.使用默认布局,就可以了.

The folder structure is also merely a matter of taste; go with the default layout and you should be fine.

这篇关于使用Scala在Play Framework中进行路由的最佳做法是哪种方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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