Java 如何在Grails URL映射中设置默认URL?

Java 如何在Grails URL映射中设置默认URL?,java,spring-mvc,grails,groovy,grails-2.0,Java,Spring Mvc,Grails,Groovy,Grails 2.0,我想为Grails包含一个默认url映射。也就是说,如果请求的url在url映射中没有规则,则应将其重定向到home/index 我的url映射当前为: class UrlMappings { static mappings = { "/$controller/$action?/$id?(.$format)?" { constraints { // apply constraints here }

我想为Grails包含一个默认url映射。也就是说,如果请求的url在url映射中没有规则,则应将其重定向到home/index

我的url映射当前为:

class UrlMappings {

    static mappings = {
       "/$controller/$action?/$id?(.$format)?" { 
           constraints { 
           // apply constraints here
           } 
        }

       "/"(controller:"home", action:"index")

       "/admin"(controller:"login",action:"authadmin")
       "/robots.txt"(controller:"home",action:"robots")
       "/sitemap.xml"(controller:"home",action:"sitemap")

       "404"(controller:"home",action:"notfound")
       "500"(view:'/error')

       "/**"(controller:"home", action:"index")    
    }
}
我使用以/**开头的最后一条规则来映射url映射中没有特定规则的所有传入请求。问题是当我在GSP文件中放入以下内容时

<g:link controller="home" action="index"><div class="MainLogo"></div></g:link>

有没有办法纠正这个问题?在url映射中没有定义规则的情况下,如何为url创建默认映射?

我不能说我真的建议这种方法,因为对于不存在的页面,最好发送404返回,但无论如何,我认为最好的方法是使用双通配符路径。见:

例如:

   "/$path**"(controller:"home", action:"index")

有没有办法从这个规则中排除一些URL?@confile,也许这会有帮助。是的,你可以应用约束。请参阅@graemorecher我对您的解决方案有一些问题,我得到了“SyntaxError:意外令牌”
   "/$path**"(controller:"home", action:"index")