我在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")
index
(与断字问题有关:https://stackoverflow.com/a/29737608)。
关于grails - 路由到webapp文件夹时,将默认渲染文件设置为grails 3中的index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30132373/