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
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值