Grails - 如何定义起始索引页 URL

Grails - How to define the starting index page URL

在 grails 中,假设您有一个名为 'MainProject' 的项目,我的默认索引是 http://localhost:8080/MainProject/ 并且与这个 url 关联的页面是 views/index.gsp

我希望项目的开始 link 不是 http://localhost:8080/MainProject/,而是类似于 http://localhost:8080/MainProject/users/login

我尝试编辑 URL 映射:

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(view: '/index')
        "500"(view:'/error')
    }
}

对此:

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(view: '/users/login')
        "500"(view:'/error')
    }
}

经过上述修改后,通过启动项目,url仍然是http://localhost:8080/MainProject/,但显示的页面不是views/index.gsp 但是 views/users/login.gsp。 gsp 已正确呈现,但 url 仍然不是我需要的。

如何解决?

您可以使用:

"/"(redirect: '/users/login')

另见 Grails URL Mapping Documentation