开发者

Grails UrlMapping - cannot set params.id for controller

I'm trying to create a U开发者_运维知识库rlMapping to map some static URL to a controller action, but I can't seem to set params.id. I'm working through Grails in Action, so I'm not sure what's wrong here.

Code:

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

In PostController

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

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

What's wrong with the above code? I'm using grails 1.2.2.


You need to use a closure:

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

or like this :

"/timeline/$id"{
               controller = 'post'
                action = 'timeline'
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜