在我的普惠制中,我有类似的内容:
<head>
<meta property="og:image"
content="${createLink(controller:'main', action:'getImage', id:item.id, params:[width: 115, height:200], absolute : true)}" />
</head>
当我查看生成的代码时,我发现:
<meta property="og:image"
content="http://www.myurl.com/main/getImage/faf878ef93996f26c1?width=115&height=200" />
问题是里面有一些amp;值。
在我的 Controller 中:
参数如下所示:
[width:115, amp;height:200, id:faf878ef93996f26c1, action:getImage, controller:main]
问题是 params.height 不再工作了,因为有 amp;再次。
如何正确解码此网址?有没有办法让 Grails 不放置 amp;网址里面?
当我在 GSP 正文中执行以下操作时:
<body>
${createLink(controller:'main', action:'getImage', id:item.id, params:[width: 115, height:200], absolute : true)}"
</body>
我得到了正确的网址:
http://www.myurl.com/main/getImage/faf878ef93996f26c1?width=115&height=200
为什么 Grails 将这些 url 设置不同?如何解决这个问题?
最佳答案
我不知道这个问题是否仍然存在,但有人可能会遇到这个问题。因此解决方案是将链接生成的代码包装到 raw() 函数中:
<meta property="og:image"
content="${raw(createLink(controller:'main', action:'getImage', id:item.id, params:[width: 115, height:200], absolute : true))}" />
但是编码的 url 也可以工作。通常此属性用于在链接到某处共享的网站时显示图像。所以服务可以正常处理和解码它
关于grails - 正确解码 Grails URL 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410094/