【问题标题】:Grails webflow url rewritingGrails webflow url重写
【发布时间】:2011-05-04 13:21:59
【问题描述】:

希望在使用 grails webflow 时使 URL SEO 友好。它对 grails 使用的约定非常有限制,并且很难绕过它的构建方式。 例如,我在名为 FooController 的控制器中有一个名为 fooProcess 的流程,当我触发流程时,我希望显示:/foo/bar/test,而不是 /foo/fooProcess?excecution=e1s2

class FooController {
 def fooProcessFlow {
   showFoo {
   }
 }
}

我尝试使用重定向并指定 uri,但不支持,grails 抱怨找不到页面

fooProcessFlow {
 showFoo {                              
   redirect(uri:"/foo/bar/test")    
 }
}

grails/foo/fooProcess.dispatch/externalRedirect:/foo/bar/test

另外,重定向是流中的结束状态,如果我只想渲染页面,我必须使用 render 方法并指定视图名称或根据 webflow 约定构造我的视图。

fooProcessFlow {
 showFoo {                              
   render(view:"/foo/bar/test") 
   on "add".to "add"
 }
}

在这种情况下,网址将是

/foo/fooProcessProcess?execution=e6s1

以前有人处理过这个案子吗?

有没有人在 grails 中使用 UrlRweriteFilter 和 webflows http://code.google.com/p/urlrewritefilter/

肯

【问题讨论】:

    标签: grails


    【解决方案1】:

    您可以使用 URLMappings Grails 插件

    见:http://grails.org/doc/latest/ref/Plug-ins/URL%20mappings.html

    编辑这个文件:grails-app/conf/UrlMappings.groovy

    把这样的东西放进去:

    class UrlMappings {
    
        static mappings = {
    
            "/foo/bar/test" (controller: "foo", action: "fooProcessFlow")
    
            "/$controller/$action?/$ids?"{
                constraints {
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 2011-11-10
      相关资源
      最近更新 更多