grails - 路由到webapp文件夹时,将默认渲染文件设置为grails 3中的index.h

我在webapp / test文件夹中有一个index.html页面。如果我转到路径localhost:8080 / test / index.html,则页面将呈现,但如果我转到localhost:8080 / test /,则会使页面找不到错误。什么是实现此目标的正确方法?在我的UrlMappings.groovy中,我尝试了这些口味,但没有任何运气。

class UrlMappings {

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

        /* TRIED THESE 
        "/"(view: "/index.html")
        "/"(url: "/index.html")
         */
        "500"(view: '/error')
        "404"(view: '/notFound')
    }
}

最佳答案

创建您的测试 Controller ,并将HTML放在views/test/index.gsp上,然后可以使用以下方法路由到localhost:8080/test/:

"/test" (controller: "test")

如果没有上述映射指令,Grails似乎默认将操作默认为URL中的index(与断字问题有关:https://stackoverflow.com/a/29737608)。

关于grails - 路由到webapp文件夹时,将默认渲染文件设置为grails 3中的index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30132373/

相关文章:

php - 使用 PHP SSH 进入机器

grails - 三元算子的奇怪行为

amazon-web-services - AWS EC2 - 为什么连接时我的 SSH 公钥不存在

grails - 验证标准无法使用

ssh - docker run找不到名称标志参数

ssh - 如何找到在amazon-ec2中启动的实例的用户名?

json - JSON获取全数字

git - 如何在GitBlit中禁用SSH并仅使用HTTP和HTTPS

php - PHP Net_SSH2-exec()如何获取命令返回码

php - 设备的 ioctl 不合适