当用户登录(session.user)时,我想对同一URL http://localhost:8080/myapp/使用不同的映射
实际上,默认情况下,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 ..)都采用了这种方法,但是如果不使用相同的操作(例如AppControlle> index)并在用户处于使用状态时呈现不同的 View ,就无法理解如何在Grails中完成此操作。活性。
static mappings = {
"/"(controller:"app",action:"index")
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"500"(view:'/error')
"404"(view:'/notFound')
}
最佳答案
关于您对twitter,facebook的提及...我认为根据请求是POST还是GET,他们可能使用不同的映射。在Grails中,我们可以这样进行映射:
name home: "/" {
controller = [GET: "app", POST: "user"]
action = [GET: "index", POST: "userIndex"]
}
关于url - 同一网址的不同映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759893/