grails - 如何将grails 3中的动作映射到“/”?
问题描述
我正在使用 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 "/"(controller:'app'),则操作执行正常并且视图是正确的,但 URL 是http://localhost:8090/app/index
是否可以显示来自 app/index 的视图是映射到“/”的 URL?
解决方案
是否可以显示来自 app/index 的视图是映射到“/”的 URL?
是的。请参阅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>
我希望这会有所帮助。
推荐阅读
- swift - Swift 4 alamofire responseSerializationFailed
- javascript - 如何从命令参数数组中删除提到的用户?
- angular - 在 url 中发送包含 html 的字符串而不删除特殊字符
- node.js - waitUntil: 'domcontentloaded' 后并非所有 DOM 内容都准备就绪
- html - 如何使用 golang 从查询中直接导出到 CSV
- mysql - 多表间动态列名导入mySQL
- spring-boot - ResponseStatusException 永远不会返回给用户
- node.js - 无法从 node.js 写入 Firebase
- java - 关于 LeetCode 279. 完美正方形的问题
- git - 推送后Git不要求我输入用户名和密码,但我正在推送到另一个遥控器