gpt4 book ai didi

rest - createLink到休息 Controller

转载 作者:行者123 更新时间:2023-12-02 14:42:19 27 4
gpt4 key购买 nike

我已经定义了域对象

class Product implements Serializable{
String sku
static hasMany = [images: MediaContent]
}

class MediaContent implements Serializable{
[...]
}

及其扩展RestFulController的REST Controller 。特别是,ProductRestController如下:
ProductRestController类扩展了RestfulController {
static responseFormats = ['json']

ProductRestController(){
super(Product)
JSON.registerObjectMarshaller(Product){
return [
id: it.id,
media: createLink(controller:"mediaRest", id:it.imageId)
]
}

网址映射非常简单,例如
"/rest/product" (resources:"productRest")
"/rest/media" (resources:"mediaRest")

问题是使用 createLink指令生成的链接不是其余格式 /rest/media/1,而是 /rest/media/index?id=1
这两个网址在被调用时均有效,但仅生成 ?id=版本。
我也尝试了带有 resource属性的createLink,但是没有任何效果。
我该如何实现?

最佳答案

您可以在UrlMappings.groovy中进行更改

"/rest/product/$action/$id"(controller: 'productRest')

"/rest/media/$action/$id"(controller: 'mediaRest')

关于rest - createLink到休息 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28213457/

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