带有以“/”结尾的网址格式的Grails UrlMappings [英] Grails UrlMappings with URL-pattern ending with "/"

查看:222
本文介绍了带有以“/”结尾的网址格式的Grails UrlMappings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 / $ something /{
controller

在我的Grails UrlMappings类中有以下UrlMapping: =controllerName
action =actionName
constraints {
}
}

对/ foobar /和/ foobar的请求都被路由到正确的控制器和操作。 然而,URL:s使用g:link创建的链接不会像预期的那样以斜线(/)结束。



GSP代码...

 < g:link controller =controllerNameaction =actionNameparams =[something:'foobar']> ...< / g:link> ; 

...生成HTML输出...

 < a href =/ foobar> ...< / a> 

如何让Grails生成URL模式指定的链接?

解决方案

不幸的是,对于Grails的默认URL映射,这是不可能的。斜线以特殊方式处理。这个行为在Grails核心中是硬编码的。可以使用插件覆盖它。



作为解决方法(可能不适用),我可以提供以下方式使用它:

 < g:link uri =/ foobar /> Foo Link< / g:link> 

这会产生一个带有斜线的连结。


I have the following UrlMapping in my Grails UrlMappings class:

  "/$something/" {
      controller = "controllerName"
      action = "actionName"
      constraints {
      }
  }

Requests to both "/foobar/" and "/foobar" gets routed to the correct controller and action.

However, URL:s created using g:link does not end with slash ("/") as expected.

The GSP code ...

<g:link controller="controllerName" action="actionName" params="[something: 'foobar']">...</g:link>

... generates the HTML output ...

<a href="/foobar">...</a>

How do I make Grails generate the link as specified by the URL pattern? That is including the ending slash.

解决方案

Unfortunately this is not possible with Grails' default URL mapping. Slashes are handled in a special way. And this behaviour is hard-coded in the Grails core. It could be overridden using a plugin though.

As a workaround (probably not applicable) I can provide to use it that way:

<g:link uri="/foobar/">Foo Link</g:link>

This should produce a link with a trailing slash.

这篇关于带有以“/”结尾的网址格式的Grails UrlMappings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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