Grails urlmapping using id and name

心已入冬 提交于 2019-12-23 15:37:38

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/5179265/grails-urlmapping-using-id-and-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!