哪种方式是使用 Scala 在 Play Framework 中进行路由的更好做法?

which way is a better practice for routing in Play Framework with Scala?

https://github.com/wsargent/play-jdk13-alpine-slim/blob/master/src/main/scala/com/example/myservice/AppComponents.scala

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种指定路线的方式,如上图,推荐哪种方式?哪个文件夹结构更好?

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

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

没有明显的优势。使用路由文件通常更简洁 "easier",但在使用 DSL 将路由绑定到某些操作时,您可以更好地控制。

文件夹结构也只是个人喜好问题;使用默认布局应该没问题。