同一网址的不同映射

时间:2011-04-22 20:48:04

标签: url grails mapping

当用户登录时,我想为同一个网址http://localhost:8080/myapp/使用不同的映射(session.user)

实际上,默认情况下我m giving the path when the url is "/" to AppController and 'index' action... but if I try to redirect inside the index action when the user is logged to my UserController (also index action), the path changes to http://localhost:8080/myapp/user/index . That不是我想要的。

有很多网站(twitter,facebook ..)应用这种方法,但是无法理解如何在Grails中完成,而不使用相同的操作(例如AppControlle> index)并渲染不同的视图当用户处于活动状态时。

 static mappings = {
    "/"(controller:"app",action:"index")

    "/$controller/$action?/$id?"{
      constraints {
        // apply constraints here
      }
    }

    "500"(view:'/error')
    "404"(view:'/notFound')
  }

1 个答案:

答案 0 :(得分:1)

关于你提到的关于twitter,facebook ...我认为他们可能根据请求使用不同的映射是POST或GET。在Grails中,我们可以像这样进行这种映射:

name home: "/" {
    controller = [GET: "app", POST: "user"]
    action = [GET: "index", POST: "userIndex"]
}