小编tyl*_*ern的帖子

在Grails中发布嵌套资源的问题

我在理解Grails Restful控制器如何工作方面遇到了问题.我正在尝试向嵌套资源发布帖子请求(见下文).我不确定我是否理解我需要更改以使其工作,因为看起来GET请求与其父资源项建立Bid的关联,但是当我尝试POST时,我被警告该项不能为空.

任何帮助表示赞赏!

Item.groovy

class Item {
    static hasMany = [bids:Bid]
}
Run Code Online (Sandbox Code Playgroud)

Bid.groovy

class Bid {
    Integer ownerId
    Double amount

    static belongsTo = [item:Item]

    static constraints = {
        ownerId nullable: false
        amount nullable: false
    }
}
Run Code Online (Sandbox Code Playgroud)

BidController.groovy

class BidController extends RestfulController<Bid> {
    static responseFormats = ['json', 'xml']
    BidController() {
        super(Bid)
    }
    @Override
    def getObjectToBind() {
        request.parameterMap.put('itemId', params.itemId)
        return request
    }
}
Run Code Online (Sandbox Code Playgroud)

ItemController.groovy

class ItemController extends RestfulController<Item> {
    static responseFormats = ['json', 'xml']
    ItemController() {
        super(Item)
    }
}
Run Code Online (Sandbox Code Playgroud)

UrlMappings.groovy

class UrlMappings …
Run Code Online (Sandbox Code Playgroud)

java rest grails groovy grails-orm

6
推荐指数
1
解决办法
1683
查看次数

标签 统计

grails ×1

grails-orm ×1

groovy ×1

java ×1

rest ×1