Grails UrlMappings with URL-pattern ending with “/”

*爱你&永不变心* 提交于 2019-12-22 10:34:53

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/631490/grails-urlmappings-with-url-pattern-ending-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!