使用ID和名称的Grails url映射 [英] Grails urlmapping using id and name

查看:83
本文介绍了使用ID和名称的Grails url映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,我有一个关于grails中的urlmapping的问题。我正在尝试使用页面名称和ID来使seo友好的url。我在我的URLMapping中获得了如下结果:

  class UrlMappings {

static mappings = {
/ $ id / $ name{
controller =page
action =view
}
500(view:'/ error')
/(controller:index)
}
}

女巫正在工作,但.... id不会在urlbar中清除,所以我第一次点击链接一切顺利: http:// localhost:8080 / SuurdGasControl / 2 / Gasmetingen



但是在下一页显示: http:// localhost:8080 / SuurdGasControl / 2/6 / Ontgassen

b

请注意,ID2未被删除...



任何帮助或想法?

更新

现在URLMapping如下所示:

  class UrlMappings {

static mappings = {
/ $ controller / $ action?/ $ id? {
constraints {
//在此处应用约束
}
}

名称stfu:/ id / $ id / $ name{
controller ='page'
action ='view'
}

500(view:'/ error')
/(controller: index)

}
}

创建链接如下所示:

 < g:link mapping =stfuparams =[id:pageId,name:pageName ]> $ {oNavigationInstance.toString()}< /克:链接> 


解决方案

尝试使用< a href =http://docs.grails.org/latest/guide/theWebLayer.html#namedMappings =nofollow> http://docs.grails.org/latest/guide/theWebLayer.html#namedMappings


hey all, i have a question about urlmapping in grails. I'm trying to make seo friendly url's using a page name and id. I got the follwing in my URLMapping:

class UrlMappings {

static mappings = {
    "/$id/$name"{
        controller = "page"
        action = "view"
    }
    "500"(view:'/error')
    "/"(controller:"index")
  }
}

Witch is working, but.... the id won't clear in the urlbar, so the first time i click a link all goes well: http://localhost:8080/SuurdGasControl/2/Gasmetingen

But for the next page it shows: http://localhost:8080/SuurdGasControl/2/6/Ontgassen

note that the id "2" hasn't been removed...

Any help or thoughts?

UPDATE

URLMapping now looks like this:

class UrlMappings {

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

    name stfu: "/id/$id/$name" {
        controller = 'page'
        action = 'view'
    }

    "500"(view:'/error')
    "/"(controller:"index")

  }
}

Creating a link is as simple as:

<g:link mapping="stfu" params="[id: pageId, name: pageName]">${oNavigationInstance.toString()}</g:link>

解决方案

Try to use a named URL mapping as described on http://docs.grails.org/latest/guide/theWebLayer.html#namedMappings

这篇关于使用ID和名称的Grails url映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆