grails - Grails 4.1 - URL 映射中的静态映射在升级后无法正常工作
问题描述
我目前正在升级到 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 版本中运行良好,当我单击链接重定向到 urllocalhost:8000/tool/converters/list
时,转换器将被识别为控制器,列表将被识别为操作,并显示正确的视图。现在我已经升级了,当我单击链接时,它重定向到的 urllocalhost:8080/tool%2Fconverters/list
和错误消息“此页面不工作”是视图中显示的内容。“%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>
这两个链接似乎都按预期工作。
推荐阅读
- json - 将 JSON 数组转换为 Typescript 类属性的类型
- c# - AutoMapper 覆盖递归类型
- x86 - LLVM IR 小于或等于与否定比较
- javascript - JavaScript Click EventListener 只工作一次
- java - 如何使用scenebuilder在javafx中动态添加和删除控件
- node.js - 部署在 Heroku 上的应用程序无法打开
- scala - 将集合的流平面映射到其元素的流
- javascript - 将 html 元素复制到 shadow dom
- mysql - SQL 错误 [102] [42000]: ')' 附近的语法不正确
- extjs - EXTJS 6.0.x:增加轴和轴标签之间的空间