【发布时间】: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')
}
}
这是我的ewhetController 的show 操作:
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=abc,id 字段将映射到 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