2014-10-18 51 views
0

我有一個Grails應用,在那裏urlMappings.groovy文件的內容是:Grails的urlMappings動作和控制器行爲不使用控制器邏輯

"/" { 
    controller="home" 
    view="home" 
} 

我家的控制器看起來像

class HomeController { 
    List products = [ 
     ['price': 100, 'desc':'a'], 
     ['price': 200, 'desc':'b'] 
    ] 

    def home() { 
     [products: products] 
    } 

當我瀏覽到localhost:8080/myProject/home/home ,我有權訪問"${products}",但是當我導航到localhost:8080/myProject時,"${products}"語句爲空。

爲什麼會這樣,我怎樣才能使localhost:8080/myProject的行爲與localhost:8080/myProject/home/home一樣?

回答

4

你應該做

"/"(controller: 'home', action: 'home') 
+0

Woops!如果認爲名稱不是行動,那是什麼造成的。 – 2014-10-18 11:56:19