gpt4 book ai didi

grails - 跟随页面上的任何链接时,Grails “loses”自定义URL映射

转载 作者:行者123 更新时间:2023-12-02 14:21:25 29 4
gpt4 key购买 nike

我有一个应用程序,用户可以通过两种方式浏览 map (例如缩略图和列表中的 map )

/map/browse
/map/list

现在,我想将这些 View 限制为仅显示特定用户的 map ,例如通过
/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

另外,如果我在 Controller 中将 userId设置为 null,则会收到错误消息:

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



分页的工作方式如下:
<div class="paginateButtons">
<g:paginate controller="map" action="browse" total="${mapInstanceTotal}"></g:paginate>
</div>

我该怎么办,或者实现我想要的正确方法是什么?

我不一定需要具有该URL映射,我只需要一种很好的表达方式:“仅显示一个用户的映射”

最佳答案

看来问题不在于您的URL映射配置,而在于您创建链接的方式。我认为如果使用Named URL Mapping会更好:它比现在的方法更清晰,并且当创建分页链接时,您只需指定url名称。例如:

在UrlMappings.groovy中:

static mappings = {

name accountDetails: "/details/$acctNumber" {
controller = 'product'
action = 'accountDetails'
}
}

在 View 中-gsp页面:
<g:link mapping="accountDetails" params="[acctNumber:'8675309']">
Show Account
</g:link>

关于grails - 跟随页面上的任何链接时,Grails “loses”自定义URL映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5946909/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com