Grails。使用.gsp扩展格式的URL映射。

问题描述 投票:0回答:1

我有一个网址请求,如 www.xyz.com/customer/list.gsp

当我尝试映射网址来删除.gsp.GRAILS时,GRAILS应用程序无法识别网址,并抛出404错误。

"/customer/list.gsp"(controller: "customer") {
        action = "list"
    }

grails应用程序无法识别该网址,并抛出404错误。我是不是遗漏了什么?

grails groovy grails-plugin grails-controller grails-3.3
1个回答
0
投票

如果你想删除 .gsp 那么你可以使用这样的映射......

"/customer/list"(controller: "customer") {
        action = "list"
}

你也可以这样做...

"/customer/list"(controller: "customer", action: "list")

如果你想为控制器中的所有动作生成一个映射,你可以这样做。

"/customer/$action"(controller: "customer")

默认生成的映射包括 "/$controller/$action" 允许你映射到任何控制器中的任何动作。

有了这些,你就可以发送一个请求到 /customer/list 就可以了。


0
投票

更新:显然,映射到GSP是可以的。 我仍然认为下面的信息可能会有帮助,所以我把答案留了下来,但也许我误解了你的问题。

原先的回答。

你根本不应该映射或请求GSPs。 它们是用来生成视图的,但在没有渲染的情况下是无法查看的。

取而代之的是,去像这样的url www.xyz.com/customer/list 并作图

"/customer/list" (controller: "customer") {
    action = "list"
}

甚至更好的是,你不需要为每个端点定制映射。 像这样的默认值就可以了。

"/$controller/$action?/$id?" { }

你的CustomerController将呈现 list.gsplist 行动:

© www.soinside.com 2019 - 2024. All rights reserved.