gpt4 book ai didi

rest - 未找到嵌入变量的 Grails URLMapping

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

我有一个包含以下结构的 URLMapping.groovy 文件:

class UrlMappings {
static mappings = {
"/someThing" (resources: "someThingApi", includes: ["index", "show", "create", "update", "delete"]) {
"/nestedThing/$type?" (controller: "someThingApi", action: [GET: "showNestedThing"])
}
}

当我这样调用 REST 接口(interface)时,它工作正常(调用 showNestedThing 函数):GET/someThing/{id}/nestedThing,但是当我尝试调用 GET/someThing/{id}/nestedThing/{type} 我得到以下答复:
{
"timestamp": 1445247531624,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/someThing/1/nestedThing/someType"
}

而不是它调用函数,我可以通过按预期执行 params.type 来获取 someType 。如果我检查我的 grails url 映射 (grails url-mappings-report) /someThing/${someThingId}/nestedThing/null?显示而不是预期的 /someThing/${someThingId}/nestedThing/${type}? .

使用 Grails 3.0.9。

最佳答案

虽然不理想并且没有回答我的原始问题,但有一种解决方法可以解决我的问题,即删除嵌套的 URLMapping 并稍后在 URLMapping 文件中添加它:

class UrlMappings {
static mappings = {
"/someThing" (resources: "someThingApi", includes: ["index", "show", "create", "update", "delete"]) {
"/nestedThing/$type?" (controller: "someThingApi", action: [GET: "showNestedThing"])
}
}

变成:
class UrlMappings {
static mappings = {
"/someThing" (resources: "someThingApi", includes: ["index", "show", "create", "update", "delete"])
"/something/${someThingApiId}/nestedThing/${nestedThingApiId}?" (controller: "someThingApi", action: [GET: "showNestedThing"])
}
}

这暂时解决了这个问题,但没有回答为什么我的原始嵌套代码不起作用的问题。

关于rest - 未找到嵌入变量的 Grails URLMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33212567/

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