Grails 4.1 - URL 中的静态映射升级后映射无法正常工作
Grails 4.1 - Static Mapping in URL Mappings not working properly after upgrade
我目前正在升级到 Grails 4.1。在过去的版本中,我的 URL Mappings.groovy 中有一个静态映射,如下所示:
class UrlMappings {
static mappings = {
name tool: "tool/$controller/$action?/$id?"{
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
}
"/"(controller: "auth", action: "login")
"500"(view:'/error')
"404"(view:'/notFound')
}
}
这在以前的 Grails 版本中运行良好,当我单击 link 重定向到 url localhost:8000/tool/converters/list
时,转换器将被识别为控制器,列表将是被识别为动作,并且将显示正确的视图。现在我已经升级了,当我点击 link 时,它重定向到的 url 是 localhost:8080/tool%2Fconverters/list
并且错误消息 "This page isn't working" 是视图中显示的内容。 “%2F”以某种方式插入到 url 中,导致页面无法显示。
我查看了 Grails 4 文档,但没有看到任何迹象表明 URL 映射中的静态映射格式已更改。有谁知道为什么会发生这种情况以及我该如何解决?
在 https://github.com/jeffbrown/rookycodermapping 查看项目。
package rookycodermapping
class SchemaController {
def show() {
render 'This is being rendered by the show action in SchemaController.'
}
}
package rookycodermapping
class UrlMappings {
static mappings = {
name tool: "/tool/$controller/$action?/$id?" {}
"/"(view:"/index")
"500"(view:'/error')
"404"(view:'/notFound')
}
}
<p>
Click <g:link action="show" controller="schema">here</g:link> to invoke the show action (g:link action="show" controller="schema").
Click <g:link uri="/tool/schema/show">here</g:link> to invoke the show action (g:link uri="/tool/schema/show").
</p>
这两个链接似乎都按预期工作。
我目前正在升级到 Grails 4.1。在过去的版本中,我的 URL Mappings.groovy 中有一个静态映射,如下所示:
class UrlMappings {
static mappings = {
name tool: "tool/$controller/$action?/$id?"{
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
}
"/"(controller: "auth", action: "login")
"500"(view:'/error')
"404"(view:'/notFound')
}
}
这在以前的 Grails 版本中运行良好,当我单击 link 重定向到 url localhost:8000/tool/converters/list
时,转换器将被识别为控制器,列表将是被识别为动作,并且将显示正确的视图。现在我已经升级了,当我点击 link 时,它重定向到的 url 是 localhost:8080/tool%2Fconverters/list
并且错误消息 "This page isn't working" 是视图中显示的内容。 “%2F”以某种方式插入到 url 中,导致页面无法显示。
我查看了 Grails 4 文档,但没有看到任何迹象表明 URL 映射中的静态映射格式已更改。有谁知道为什么会发生这种情况以及我该如何解决?
在 https://github.com/jeffbrown/rookycodermapping 查看项目。
package rookycodermapping
class SchemaController {
def show() {
render 'This is being rendered by the show action in SchemaController.'
}
}
package rookycodermapping
class UrlMappings {
static mappings = {
name tool: "/tool/$controller/$action?/$id?" {}
"/"(view:"/index")
"500"(view:'/error')
"404"(view:'/notFound')
}
}
<p>
Click <g:link action="show" controller="schema">here</g:link> to invoke the show action (g:link action="show" controller="schema").
Click <g:link uri="/tool/schema/show">here</g:link> to invoke the show action (g:link uri="/tool/schema/show").
</p>
这两个链接似乎都按预期工作。