gpt4 book ai didi

grails - URL映射在Grails 1.3.7中进行了更改吗?

转载 作者:行者123 更新时间:2023-12-02 14:38:05 24 4
gpt4 key购买 nike

情况:

假设我有一个名为AccountController的示例 Controller ,其中包含一些显示,编辑和更新操作。

在Grails URL映射中,我尝试按例如方法类型进行映射获取帖子等

然后,我有一个指向 Controller 的相应操作的链接,如下所示:

<g:link controller="account" action="edit">Edit my account link</g:link>

,其映射为:
"/profile"      (controller: "account", action: "show")
"/profile/edit" (controller: "account", action: [GET: "edit", POST: "update"])

这里的问题是所生成的链接应该使用映射进行查找,并使其看起来像这样,即在生成的html页面中为 “/ profile / edit” ,但是该页面具有 “/ account / edit” 到映射的映射不存在,因此单击时仅会导致错误。

我什至尝试了以下语法:
"/profile/edit" (controller: "account") { action = [GET: "edit", POST: "update"] }

但它仍指向不存在的网址映射。

这是一个错误还是只是我过得不好?

最佳答案

我不知道此方法(带有HTTP方法的反向URL映射)在Grails的早期版本中是否有效,但是我在1.3.7中重现了您的问题,我想出的唯一解决方案是使用named URL mappings。使用它,您的标签将是:

<g:link controller="account" action="edit" mapping="profileEditing">
Edit my account link
</g:link>

并且编辑映射将是:
name profileEditing: "/profile/edit" (controller: "account") {
action = [GET: "edit", POST: "update"]
}

问候。

关于grails - URL映射在Grails 1.3.7中进行了更改吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568907/

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