为什么我在grails g:link标签创建的链接末尾看到双星号? [英] Why do I see double asterisk at the end of links created by grails g:link tag?

查看:112
本文介绍了为什么我在grails g:link标签创建的链接末尾看到双星号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

The code like this:

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

产生下一个链接:

produces the next link:

<a href="/shop/categories/show/1/**">Test category</a>

为什么会发生这种情况,以及如何删除这个看起来不好看的双星号?

Why does it happen and how to remove this bad-looking double asterisk?

推荐答案

来自您的评论:

From your comment:


URLMappings包含 /类别/ $动作?/ $ ID?/ **?。但我真的很想告诉Grails,我不关心URL是否包含了一些不必要的部分。

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.

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

Unbound wildcards (* and **) do the right thing for "forward" URL mappings (i.e. taking an incoming request URI and mapping it to a controller action with parameters) but, looking at the source code for the default RegexUrlMapping, if you try to use such a mapping in reverse the * and ** components will be included literally in the generated URL. In order to be able to generate sensible URLs every segment of the mapping must be either a literal or bound to a named variable, so the generator can know what (possibly empty) value it should use to replace the wildcard.

如果您使用映射

If you were to use the mapping

"/categories/$action?/$id?/$path**?"

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

then it would still match the same URIs in forward mode (storing the trailing portion of the URI after the id in params.path) but <g:link controller="category" action="show" id="${category.id}"> will know to use an empty trailing component because you didn't specify params="[path:'something']".

这篇关于为什么我在grails g:link标签创建的链接末尾看到双星号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆