Grails“输了”跟随页面上的任何链接时自定义 URL 映射
我有一个应用程序,用户可以通过两种方式浏览地图(例如缩略图和列表)
/map/browse
/map/list
现在,我想将这些视图限制为仅显示特定用户的地图,例如通过
/user/3/browse
/user/3/list
因此我创建了映射:
"/user/$userId/browse" {
controller = "map"
action = "browse"
}
"/user/$userId/list" {
controller = "map"
action = "list"
}
现在,我可以转到 /user/3/browse
,但是一旦我点击分页链接或更改分页过滤器,URL 就会返回到 /map/browse
。
另外,如果我在控制器中将 userId
设置为 null
,则会收到错误:
错误 500:处理 GroovyPageView 时出错:执行标记时出错:无法创建用于映射 [/user/(*)/list] 和参数 [["action":"list", "controller":"map", “max”:20,“offset”:0,“sort”:“uploadDate”,“order”:“desc”,“userId”:null,“totalMaps”:30]]。参数 [userId] 是必需的,但未指定!在/views/map/browse.gsp:26
分页的工作原理如下:
<div class="paginateButtons">
<g:paginate controller="map" action="browse" total="${mapInstanceTotal}"></g:paginate>
</div>
我可以对此做什么,或者实现我想要的内容的正确方法是什么?
我不一定需要 URL 映射,我只需要一种好的表达方式:“仅显示一个用户的地图”
I have an application where users can browse maps in two ways (like thumbnails and in a list)
/map/browse
/map/list
Now, I would like to restrict these views to just show maps of a specific user, for example through
/user/3/browse
/user/3/list
So I created the mapping:
"/user/$userId/browse" {
controller = "map"
action = "browse"
}
"/user/$userId/list" {
controller = "map"
action = "list"
}
Now, I can go to /user/3/browse
, but as soon as I click on a pagination link or change the pagination filters, the URL goes back to /map/browse
.
Also, if I set the userId
to null
in the controller, I get the error:
Error 500: Error processing GroovyPageView: Error executing tag : Unable to create URL for mapping [/user/(*)/list] and parameters [["action":"list", "controller":"map", "max":20, "offset":0, "sort":"uploadDate", "order":"desc", "userId":null, "totalMaps":30]]. Parameter [userId] is required, but was not specified! at /views/map/browse.gsp:26
The pagination works as follows:
<div class="paginateButtons">
<g:paginate controller="map" action="browse" total="${mapInstanceTotal}"></g:paginate>
</div>
What can I do against that or what would be the correct way of implementing what I want?
I don't necessarily need to have that URL mapping, I only need a nice way of saying: "Display maps of only one user"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来问题不在于您的 URL 映射配置,而在于您创建链接的方式。我认为如果您使用 命名 URL 映射< /a> :它比你现在的方法更清晰,当创建分页链接时,你只需要指定 url 名称。例如:
在 UrlMappings.groovy 中:
在视图 - gsp 页面中:
It seems that the problem is not at your URL mapping configuration ,but in your way to create link. I think it's better if you use Named URL Mapping : it's clearer than your approach now, and when create link for pagination you only need to specify the url name. For example:
In UrlMappings.groovy:
In view - gsp page: