Grails 圣杯2&x2B;url映射特定规则 编辑 我忘记了一个“/”,所以它实际上在工作。我不会删除此帖子,因为它可能对其他人有用

Grails 圣杯2&x2B;url映射特定规则 编辑 我忘记了一个“/”,所以它实际上在工作。我不会删除此帖子,因为它可能对其他人有用,grails,grails-2.0,url-mapping,Grails,Grails 2.0,Url Mapping,我已经阅读了很多关于grails urlMapping的答案,但没有找到任何适合我需要的答案 假设我有两个领域:Project和Contributor class Project{ String name; String urlName; //is the name converted to url static belongsTo = [contributor: Contributor] } //a contributor has many Projects, then i

我已经阅读了很多关于grails urlMapping的答案,但没有找到任何适合我需要的答案

假设我有两个领域:
Project
Contributor

class Project{
   String name;
   String urlName; //is the name converted to url
   static belongsTo = [contributor: Contributor]
}

//a contributor has many Projects, then in the `Project` 
//table I have `contributor_id`
class Contributor{
    String userName;
    static hasMany = [projets: Project]
}
我的URL如下所示:

www.mysite.com/frank/frank-s-nice-project/comments
www.mysite.com/bill/bill-s-great-project/comments
www.mysite.com/lucie/lucie-s-awesome-project/comments
对应于:www.mysite.com/用户名/urlName/comments

用户名
来自贡献者域。
urlName
来自项目

当url匹配
“/$username/$urlName/comments”时,如何将
urlmappgins.groovy
设置为始终重定向到相同的
控制器/操作

我试过这样做,但没有成功

static mappings = {
    "/$username/$urlName/comments"(controller: 'comment', action: 'index)
}
谢谢你的帮助

static mappings = {
    "/comments/$username/$urlName"(controller: 'comment', action: 'index)
}
如果将注释替换为第一个值并进行注释,然后解析用户名/url,会发生什么情况


我在您的初始映射中看到的问题是,用户名将与您项目的实际操作冲突

我回答我的问题,使其成为公认的答案

这确实有效

static mappings = {
    "/$username/$urlName/comments"(controller: 'comment', action: 'index)
}

你看到编辑了吗?它实际上在工作。但是谢谢你的回答