简体   繁体   English

Grails:URL 映射与.gsp 扩展名/格式

[英]Grails: URL mapping with .gsp extension/format

I have a url request like www.xyz.com/customer/list.gsp我有一个 url 请求,例如www.xyz.com/customer/list.gsp

When I try to map the url to remove.gsp:当我尝试 map url 删除.gsp:

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

grails application won't recognize the url and is throwing 404 error. grails 应用程序无法识别 url 并引发 404 错误。 Am I missing something here?我在这里错过了什么吗?

Update: apparently it is fine to map to GSPs.更新:显然 map 到 GSP 是可以的。 I still think that the info below may be helpful so I'm leaving the answer up, but perhaps I have misunderstood your question.我仍然认为下面的信息可能会有所帮助,所以我将答案留在上面,但也许我误解了你的问题。

Original response:原始回复:

You shouldn't be mapping to or requesting gsps at all. 您根本不应该映射或请求 gsps。 They're used to generate views, but are not viewable without rendering. 它们用于生成视图,但在没有渲染的情况下是不可见的。

Instead, go to url like www.xyz.com/customer/list and map that like相反,go 到 url 就像www.xyz.com/customer/list和 map 一样

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

Or even better, you don't need a custom mapping for each endpoint.甚至更好的是,您不需要每个端点的自定义映射。 A default like this will work:像这样的默认设置将起作用:

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

Your CustomerController will render the list.gsp in the list action.您的 CustomerController 将在list操作中呈现list.gsp

If you want to remove .gsp from the url then you can use a mapping like this...如果您想从 url 中删除.gsp ,那么您可以使用这样的映射...

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

You could also do this...你也可以这样做...

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

If you want 1 mapping for all the actions in the controller, you could do this:如果您想为 controller 中的所有操作进行 1 个映射,您可以这样做:

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

The default generated mapping includes "/$controller/$action" which allows you map to any action in any controller.默认生成的映射包括"/$controller/$action" ,它允许您从 map 到任何 controller 中的任何操作。

With any of that, sending a request to /customer/list would work.有了这些,向/customer/list发送请求就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM