如何将 grails 3 中的动作映射到“/”?
How to map an action in grails 3 to "/"?
我正在使用 Grails 3.3.10 并尝试将“/”映射到控制器操作,用户在成功登录后被重定向。
在 UrlMappings 中我有:
class UrlMappings {
static mappings = {
"/"(controller:'app')
...
...
当用户登录时,应用程序被重定向到根 http://localhost:8090/,但它显示了从 Grails 生成的视图:
Welcome to Grails
Congratulations, you have successfully started your first Grails
application! At the moment this is the default page, feel free to
modify it to either redirect to a controller or display whatever
content you may choose. Below is a list of controllers that are
currently deployed in this application, click on each to execute
its default action:
Available Controllers:
....
我删除了默认 index.gsp 和 main.gsp 布局,但带有控制器的视图仍然出现,我无法执行我的操作。
如果我删除 UrlMapping“/”(控制器:'app'),操作执行正常并且视图是正确的,但是 URL 是 http://localhost:8090/app/index
是否可以显示来自 app/index 的视图作为 URL 映射到“/”?
Is it possible to display the view from app/index being the URL mapped
to "/"?
是的。在 https://github.com/jeffbrown/pablopazosurlmapping.
查看项目
package pablopazosurlmapping
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/"(controller:'app')
"500"(view:'/error')
"404"(view:'/notFound')
}
}
package pablopazosurlmapping
class AppController {
def index() {
[name: 'Pablo']
}
}
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Demo</title>
</head>
<body>
<h2>${name} Was Here!</h2>
</body>
</html>
希望对您有所帮助。
我正在使用 Grails 3.3.10 并尝试将“/”映射到控制器操作,用户在成功登录后被重定向。
在 UrlMappings 中我有:
class UrlMappings {
static mappings = {
"/"(controller:'app')
...
...
当用户登录时,应用程序被重定向到根 http://localhost:8090/,但它显示了从 Grails 生成的视图:
Welcome to Grails
Congratulations, you have successfully started your first Grails
application! At the moment this is the default page, feel free to
modify it to either redirect to a controller or display whatever
content you may choose. Below is a list of controllers that are
currently deployed in this application, click on each to execute
its default action:
Available Controllers:
....
我删除了默认 index.gsp 和 main.gsp 布局,但带有控制器的视图仍然出现,我无法执行我的操作。
如果我删除 UrlMapping“/”(控制器:'app'),操作执行正常并且视图是正确的,但是 URL 是 http://localhost:8090/app/index
是否可以显示来自 app/index 的视图作为 URL 映射到“/”?
Is it possible to display the view from app/index being the URL mapped to "/"?
是的。在 https://github.com/jeffbrown/pablopazosurlmapping.
查看项目package pablopazosurlmapping
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/"(controller:'app')
"500"(view:'/error')
"404"(view:'/notFound')
}
}
package pablopazosurlmapping
class AppController {
def index() {
[name: 'Pablo']
}
}
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Demo</title>
</head>
<body>
<h2>${name} Was Here!</h2>
</body>
</html>
希望对您有所帮助。