Grails URL映射导致GSP出错 [英] Grails URL mapping cause error on GSP
本文介绍了Grails URL映射导致GSP出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址与此类似:
/ mysite / admin / controller / action / id
/ mysite / search / controller / action / id
/ mysite / user / controller / action / id
我有我的URL映射像这样
/ $ prefix / $ controller / $ action?/ $ id ?{
constraints {}
}
我能够得到控制器正确。
但是在GSP方面
< g:链接控制器=控制器> abc< / g:链接> ==> < a href =/ mysite / controller /...\"> abc< / a>
注意我在mysite和控制器之间失去了前缀。
解决方案
您可以使用作为参数的一部分:
URLMappings: 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/id
I 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出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文