url - 同一网址的不同映射

标签 url grails mapping

当用户登录(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/

相关文章:

php - Ajax 找不到网址

grails - 如何将系统属性传递给Grails 3数据库迁移命令

java - 将对象映射到多个属性 (Java)

java - 如何使用mapstruct映射到List<>

grails - 当我在多选组件中取消选择一个项目时,无法删除数据库

html - css 中的图像 map 标题?

java - 将 wsit-client.xml 中的位置导入到另一个 jar 中的文件,使用 URL 字符串在类路径上定位文件

php - 如何从绝对文件夹路径获取 URL?

php - htaccess 重定向 URL 与 mysql 字段相关

grails - Grails JSON View :不透明的 View 选择-在另一个目录中选择默认模板