Grails UrlMapping

阅读更多

由于想在项目访问时通过二级目录的方式对请求进行相应的处理,所以查了些关于UrlMapping的资料,做了下总结 

 

格式:“/controll/action”(controll : "", action : "")

            "/controll/action"{

                  controll : "",

                  action : ""

             }

 

当以$开头时,表示以变量的形式传递对应值,可以在action中获取

"/controll/$action"(controll : "test", action : "index")   在index中以params.action 的方式获取$action对应的参数    

 

动态构造

当路径中包含“?”时,表示当前路径可选,但是“?”只能出现在连接的尾部

"/controll/action?" 正确    "/controll?/action"  不正确

 

通配符

*表示所有字符     "/images/*.jpg"(controllers:"image")

同样还可以使用**来映射多级目录"/images/**.jpg"(controllers:"image")

 

匹配以某些字符结尾的链接

"/$name${'Enroll'}/$action?"  匹配以“Enroll”结尾的链接

 

static mappings = {
        "/$controller/$action?/$id?" {
            constraints {
                // apply constraints here
            }
        }
        "/$accountAlias/$name${'Enroll'}/$action?"(controller: "system", action: "transmit")
        "/"(controller: "system",action:"index")
        "/index.gsp"(controller: "system",action:"index")
        "500"(view: '/error')       //grails-app/views/error.gsp
        "404"(view: "error404")      //grails-app/views/error404.gsp
    }

你可能感兴趣的:(Grails,UrlMapping)