2

我正在尝试创建一个 UrlMapping 以将一些静态 URL 映射到控制器操作,但我似乎无法设置params.id. 我正在使用Grails in Action,所以我不确定这里出了什么问题。

代码:

class UrlMappings
...
static mappings={
    "/timeline/chuck_norris"(controller:'post',action:'timeline',id:'chuck_norris')
...
}

在 PostController 中

def timeline{
   def user = User.findByUserId(params.id)
   [user:user]
}

错误: No signature of method: ...findByUserId() is applicable for argument types: () values: []

上面的代码有什么问题?我正在使用 grails 1.2.2。

4

1 回答 1

3

您需要使用闭包:

"/timeline/chuck_norris"{
            controller = 'post'
            action = 'timeline'
           id = 'chuck_norris"
        }

或像这样:

"/timeline/$id"{
               controller = 'post'
                action = 'timeline'
}
于 2010-04-22T07:35:43.173 回答