Grails - 将参数添加到 params 映射

发布于 2024-12-10 06:50:22 字数 505 浏览 0 评论 0原文

我想向我的 params 映射添加一个参数,并将其余参数绑定在链接中。目前,我仅按如下方式绑定 params

<g:link class="email" controller="administrator" action="test" params="${params}">Link text</g:link>

How can I add aparameter to the params map ?

预先感谢您的帮助。 问候,

编辑:

好的,我找到了一种方法。

params="${params + ['forwardURI': request.forwardURI]}"

我不知道是否还有其他类似 Grails 的方法可以做到这一点。如果有的话,我有义务学习它;)

I would like to add a single parameter to my params map, and bind the rest in a link. At the moment, I only bind the params classically as follows:

<g:link class="email" controller="administrator" action="test" params="${params}">Link text</g:link>

How could I add a parameter to the params map ?

Thank you in advance for you help.
Regards,

EDIT:

Ok, I have find a way to do it.

params="${params + ['forwardURI': request.forwardURI]}"

I do not know if there is any more Grails-like way to do it. If there is one, I would be obliged to learn it ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-12-17 06:50:22

如果您必须重复执行此操作,您可以使用您在 g:link 包装标签库中发布的答案,因为标签库可以访问 params请求

def forwardAwareLink = { attr, body ->
    attr.params = params + ['forwardURI': request.forwardURI]
    out << g.link(attr, body)
}

在 gsp 中:

<g:forwardAwareLink class="email" controller="administrator" action="test">Link text</g:forwardAwareLink>

如果您想将标签与 gsp 中您自己的自定义参数映射一起使用,您还可以在标签库中使用以下内容:

attr.params = attr.params + ['forwardURI': request.forwardURI]

If you have to do this repeatedly, you could use the answer you've posted in a g:link wrapper Tag Library, as Tag Libraries have access to params and request.

def forwardAwareLink = { attr, body ->
    attr.params = params + ['forwardURI': request.forwardURI]
    out << g.link(attr, body)
}

And in the gsp:

<g:forwardAwareLink class="email" controller="administrator" action="test">Link text</g:forwardAwareLink>

If you want to use the tag with your own custom parameter map from the gsp, you can also use the following in the Tag Library:

attr.params = attr.params + ['forwardURI': request.forwardURI]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文