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