代码之家  ›  专栏  ›  技术社区  ›  anishroniyar

gsp链接将命名参数和映射放在同一个params属性中

  •  0
  • anishroniyar  · 技术社区  · 8 年前

    g:link .

    我可以放置命名参数,例如:

    <g:link action="action" controller="controller" params='[hello:"hello",world:"world"]'>test</g:link>
    

    或者我可以在控制器中绘制地图,并在gsp链接参数中使用,例如:

    <g:link action="action" controller="controller" params='${testParam}'>test</g:link>
    

    <g:link action="action" controller="controller" params='${testMapParam},[hello:"hello",world:"world"]'>test</g:link>
    

    1 回复  |  直到 4 年前
        1
  •  1
  •   V H    8 年前

    有时你真的无法战胜简单:

    def test() {
        def map1=['a':1]
        def map2=['a2':2]
    
        def map3=map1+map2
        println "000 ${map3} vs ${params}"
    
        render  view:'test', model:[map1:map1,map2:map2]
    }
    

    将地图传递给view gsp:

       <g:set var="map6" value="${[hello1:'hello2',world1:'world2'] }"/>
    <g:set var="currentParams" value="${params}"/>
    ${map1 } ${map6}
    <g:link action="test" controller="test" params="${map1+map6+map2+currentParams}">test</g:link>
    

    当我点击链接时显示 {a=1}{hello1=hello2,world1=world2}测试

    点击后我的url是:

    /test?a=1&hello1=hello2&world1=world2&a2=2&hello=hello&world=world
    000 [a:1, a2:2] vs [hello:hello, a:1, a2:2, world1:world2, hello1:hello2, world:world, action:test, controller:test]
    

    你想做什么?不