如何在 play scala 中进行从子控制器到子路由的反向路由?

How to do reverse routing from subcontroller to the sub routes in play scala?

我已经从主路由创建了子路由,并且我已经创建了子控制器包,例如 controllers.subcontrollers。现在如何从子控制器访问我的子路由。

您可以使用这个访问:

// Redirect to /hello/Bob
def helloBob = Action {
  Redirect(routes.Application.hello("Bob"))
}

如您在 playframework 文档中所见。

https://playframework.com/documentation/2.3.x/ScalaRouting

但是,如果你的意思是你有多个控制器并将它们分成包并希望在另一个控制器中访问它们。你可以使用这样的东西来实现它:

controllers.packageName.routes.ControllerName.functionInsideController

尝试创建一条新路线例如:subcontrollers.routes

main routes Ex:
-> /subcontrollers  subcontrollers.Routes

subcontrollers.routes Ex:
    # Map static resources from the /public folder to the /assets URL path
    GET    /assets/*file                            controllers.subcontrollers.Assets.at(path="/public", file)

    GET    /example                           controllers.subcontrollers.SubController.sample(parameter1:Long,parameter2: String)

Reference Link