Grails - 使用Routes隐藏/ index Action

Bud*_*Joe 14 grails routes url-routing

在Grails应用程序中使用路径隐藏/ index操作的正确方法是什么?

我希望能够重定向到控制器:"profile",action:"index"但是网址看起来像
http://foobar.com/profile
而不是
http://foobar.com/profile/index

小智 13

UrlMappings.groovy

static mappings = {
      "/profile"(controller:"profile", action: "index")
}
Run Code Online (Sandbox Code Playgroud)

或者您可以在Controller中设置默认操作

class BookController {
    static defaultAction = "index"
}
Run Code Online (Sandbox Code Playgroud)

如果您想要从控制器中的操作中重定向到该URL,请执行此操作.

redirect uri: '/profile'  // This one for the UrlMappings solution
Run Code Online (Sandbox Code Playgroud)

要么

redirect controller: 'profile'  // This one for the defaultAction solution.
Run Code Online (Sandbox Code Playgroud)