什么是配置设置修改默认主页在Grails应用不再是APPNAME/index.gsp中?当然,您可以将该页面设置为重定向,但必须有更好的方法。如何更改Grails应用程序中的默认主页?
回答
编辑UrlMappings.groovy
添加例如添加此规则,以处理与HomeController的根。
“/”(控制器: '家')
在UrlMappings.groovy
"/" { controller = "yourController" action = "yourAction" }
添加此通过配置URLMappings这样,应用程序的主页会yourWebApp/yourController/yourAction。
(剪切/从IntelliGrape Blog粘贴)
也许该方法在后续版本的Grails中更改,因为它在1.3.7上不起作用。使用daherman发布的语法为我工作。 – jerseyboy 2012-04-05 01:45:40
简洁明快
转到文件:在grails-app/conf目录/ UrlMappings.groovy。
用 “/”(控制器:'home',action:“/ index”)替换该行:“/”(view:“/ index”)。
家是你的控制器运行(如在春季安全性,您可以使用“登录”)和行动是Grails的查看与控制器相关的页面(在Spring Security“/ AUTH”)。页面按您的应用需求
加入重定向。
您可以尝试作为UrlMappings.groovy类是配置文件夹内如下
:
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
//"/"(view:"/index")
"/" (controller:'Item', action:'index') // Here i have changed the desired action to show the desired page while running the application
"500"(view:'/error')
}
}
希望这有助于
鲁贝尔
所有的答案是正确的! 但让我们来想象一个场景:
我映射路径“/”与控制器:“家”和行动:“索引”,所以当我访问“/应用程序名称/”控制器家得到执行,但如果我输入路径“/ app-name/home/index”,它仍然会被执行!所以一个资源有两条路径。它会工作,直到有人找到“家/索引”的路径。
另一件事是,如果我有一个表格没有任何指定action属性,因此默认情况下它会POST到同一个控制器和行动!所以如果表单映射到“/”路径并且没有指定action属性,那么它将被提交给同一个控制器,但是这次路径在你的地址栏中是“home/index”,而不是“/”,因为它被提交给控制器/操作而不是URI。
为了解决这个问题,你所要做的,就是删除或注释掉这些行。
// "/$controller/$action?/$id?(.$format)?"{
// constraints {
// // apply constraints here
// }
// }
所以,现在当你访问“/”,将工作。但“家/索引”不会。但是存在一个缺陷,现在必须通过明确写入URLMapping文件来手动将所有路径映射到控制器。我想这会有所帮助!
使用控制器,查看和操作参数通过以下语法:
class UrlMappings {
static mappings = {
"/" (controller:'dashboard', view: 'index', action: 'index')
"500"(view:'/error')
}
}
工作对我来说,下Grails的1.3.7,与动作:键。 – jerseyboy 2012-04-05 01:45:59