2013-07-11 37 views
1

这里是我的URLmappings.groovyGrails的URL id字段没有得到映射到PARAMS

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/abcabc没有被映射到params.id,当我渲染params时,我得到一张空的地图[:]。在情况下,如果作为http://localhost:8080/g24/ewhet/show?id=abcid场被映射到params.id输入网址,我得到:

['id':'abc'] 

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

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

+0

如果您尝试注释掉第一个映射/$controller/$action?/$id?(.${format})?“? –

+0

@FabianoTaioli无效! – rahulserver

+0

如果您将映射更改为”/ ewhet/$ idx“(控制器:”ewhet“,动作:”显示“)它是idx在params? –

回答

1

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

+0

非常感谢你! – rahulserver

+0

Infact我找到了一个更通用的映射,它适用于我。我将这段代码添加到了urlmappings中:“/ $ controller/$ ID “(动作:” 秀“) – rahulserver