2014-06-17 62 views
0

如果在request.json一個記錄下面的代碼工作渲染JSON來的Grails域列表對象

class BookController { 
    def save = { 
     def book = new Book(JSON.parse(yourJson)) 
     book.save(flush:true) 
    } 
} 

可是如何才能讓書目,如果有我喜歡request.JSON多個記錄:

[{ 
    "id": 3, 
    "name": "MYNAME", 
    "description": "test", 
    "category": 1, 
    "venue": null, 
    "status": "Published", 
    "deleted": false, 
    "pricingPolicy": null 
}, { 
    "id": 6, 
    "name": "YZ", 
    "description": "test6", 
    "category": 2, 
    "venue": null, 
    "status": "Unpublished", 
    "deleted": false, 
    "pricingPolicy": null 
}, { 
    "id": 9, 
    "name": "YZ", 
    "description": "test6", 
    "category": 1, 
    "venue": null, 
    "status": "Published", 
    "deleted": false, 
    "pricingPolicy": null 
}] 

回答

0
request.JSON.each{ new Book(it).save() } 

應該做的