gpt4 book ai didi

grails - 为什么我在 grails g :link tag? 创建的链接末尾看到双星号

转载 作者:行者123 更新时间:2023-12-02 15:01:54 30 4
gpt4 key购买 nike

像这样的代码:

<g:link controller="category" action="show" id="${category.id}">${category.name}</g:link>

产生下一个链接:
<a href="/shop/categories/show/1/**">Test category</a>

为什么会发生这种情况以及如何删除这个难看的双星号?

最佳答案

从您的评论中:

URLMappings contains this "/categories/$action?/$id?/**?". But I really want to tell grails that I don't care if URL contains some unnecessary parts after the meaningful part.



未绑定(bind)的通配符( *** )对“转发” URL 映射(即获取传入的请求 URI 并将其映射到带有参数的 Controller 操作)做正确的事情,但是,如果您尝试查看默认 RegexUrlMapping 的源代码反向使用这样的映射, *** 组件将包含在生成的 URL 中。为了能够生成合理的 URL,映射的每个部分都必须是文字或绑定(bind)到命名变量,因此生成器可以知道它应该使用什么(可能为空)值来替换通配符。

如果您要使用映射
"/categories/$action?/$id?/$path**?"

那么它仍然会在转发模式下匹配相同的 URI(将 URI 的尾随部分存储在 id 之后的 params.path 中)但 <g:link controller="category" action="show" id="${category.id}"> 会知道使用空尾随组件,因为您没有指定 params="[path:'something']"

关于grails - 为什么我在 grails g :link tag? 创建的链接末尾看到双星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13162204/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com