在glink标记的id属性中添加多个值

时间:2014-03-09 10:07:18

标签: grails gsp

是否可以在id代码的glink属性中添加多个值?

我希望得到一个网址:/place/view/home/7?(/< controller> /< action> /< name> /< id>?params)

是否可以使用glink代码?

2 个答案:

答案 0 :(得分:2)

如果我正确理解您正在寻找的是params选项,

<g:link controller="cname" action="act" id="1" params="[sort: 'title']" />

答案 1 :(得分:0)

我在Grails v2.4.3中使用以下解决方案:

在UrlMappings.groovy中,我补充道:

static mappings = {
    ...
    name dualId: "/$controller/$action/$id/$id2?(.$format)?" {}

    /* Usage:
     *  <g:link mapping="dualId" action="myMethod" params='[id2: "${id2Value}"]'>
     *    Accept id AND id2
     *  </g:link>

     *  Generates following link in the UI: 
     *    <a href="/myController/myMethod/142/387">Accept id AND id2</a>
     *  SPECIAL NOTE: params='[id2: "${id2Value}"]' works.
     *    using: params="[id2: '${id2Value}']" DOES NOT WORK!
     */
    ...
}

根据您的要求,&#34; / place / view / home / 7? (/&lt; controller&gt; /&lt; action&gt; /&lt; name&gt; /&lt; id&gt;?params)&#34;,您可以使用:

static mappings = {
    ...
    name placeViewHome: "/$controller/$action/$name/$id?" {}

    /* Usage:
     *  <g:link mapping="placeViewHome" action="myAction" params='[name: "${nameValue}", q: "str"]'>
     *    Accept name AND id
     *  </g:link>

     *  Should generate the following link in the UI: 
     *    <a href="/myController/myMethod/myName/387?q=str">Accept name AND id</a>
     *  I didn't try it, but you should be able to add in other params and I would expect them to appear after the question mark as usual.
     */
    ...
}

有关详细信息,请参阅Grails文档8.4.11 Named URL Mappings ...

注意:在g:链接中,引号的顺序很重要,单引号内的双引号有效,但不是相反。