【问题标题】:Grails URL id field not getting mapped to paramsGrails URL id 字段未映射到参数
【发布时间】:2013-07-11 04:38:26
【问题描述】:

这是我的URLmappings.groovy

class UrlMappings {

static mappings = {
    "/$controller/$action?/$id?(.${format})?" {
        constraints {
            // apply constraints here
        }
    }
    "/ewhet/$id"(controller : "ewhet", action : "show")
    "/"(view: "/index")
    "500"(view: '/error')
    }
   }

这是我的ewhetControllershow 操作:

class EwhetController {
    def index(){

    }
    def show(){
            def ctx = startAsync()
            ctx.start {
                render params
                //render "this invoked!!"
                ctx.complete()
            }
        }
}

现在当我输入网址时:http://localhost:8080/g24/ewhet/abc abc 没有映射到 params.id 并且当我渲染 params 时,我得到一个空映射 [:] 。如果 url 输入为 http://localhost:8080/g24/ewhet/show?id=abcid 字段将映射到 params.id,我得到:

['id':'abc']

所以我只想将 url 的最后一部分映射到 params 映射中的 id 参数,而不使用 url 中的任何映射(如 id=abc),按照 Grails documentation 中的第 7.4.3 节那怎么可能?为什么我的方法不起作用?

请注意,我没有任何域类,因为我在后端使用无模式 mongodb。

【问题讨论】:

  • 如果你尝试注释掉第一个映射 /$controller/$action?/$id?(.${format})?" ?
  • @FabianoTaioli 不起作用!
  • 如果您将映射更改为 "/ewhet/$idx"(controller : "ewhet", action : "show") 它是参数中的 idx?
  • @FabianoTaioli 我已经解决了。实际上,使用修改后的 URLMappings 重新启动应用程序确实会导致配置运行。教训是 URLmappings.groovy 没有被编译。你可以把它作为关闭的答案在这里。

标签: mongodb grails urlmappings.groovy


【解决方案1】:

在更改 UrlMappings.groovy 后尝试重新加载应用程序以确保正确加载新配置。

【讨论】:

  • 事实上,我找到了一个更通用的映射,对我有用。我将此代码添加到 urlmappings:"/$controller/$id"(action:"show")
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-16
相关资源
最近更新 更多