本文介绍了Grails URL映射导致GSP出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址与此类似:
p>
名称前缀:/ $ prefix / $ controller / $ action?/ $ id?{
constraints {}
GSP:
< g:link mapping =prefixparams =[前缀:$前缀,控制器:...]> abc< / g:link>
要使用 sortableColumn ,只需将所有 params 属性中的URLMapping参数:
< g:sortableColumn property =coltitle =titleparams =[prefix:'prefix',controller:'controller',action:'action']/>
I have a site that have URL similar to this:
/mysite/admin/controller/action/id /mysite/search/controller/action/id /mysite/user/controller/action/idI have my URL mapping like this
"/$prefix/$controller/$action?/$id?"{ constraints {} }I am able to get to the controller correctly.
But on the GSP side
<g:link controller="controller">abc</g:link> ==> <a href="/mysite/controller/...">abc</a>Notice how I lose the prefix between mysite and the controller.
解决方案You can use named url mappings and then pass the prefix as part of the params:
URLMappings:
name prefix: "/$prefix/$controller/$action?/$id?"{ constraints {} }GSP:
<g:link mapping="prefix" params="[prefix:$prefix, controller:...]">abc</g:link>To use sortableColumn, just put all of the URLMapping parameters in the params property:
<g:sortableColumn property="col" title="title" params="[ prefix: 'prefix', controller:'controller', action:'action']" />
这篇关于Grails URL映射导致GSP出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!