0
我创建了两个域,作者和书,作者有很多书,而书是belongsTo作者。如何在Grails的REST Web服务中创建Json?
class Author {
hasMany = [ books : Book ]
String name
}
class Book {
String title
Author author
}
这个“savebook”功能BookController.groovy
def savebook={
def json = request.JSON
def bookInstance = new Book()
bookInstance.properties = json
bookInstance.author_id = json.author_id
bookInstance.title = json.title
if (bookInstance.validate()) {
bookInstance.save();
def rep = [ respence: "1" ] // save
render rep as JSON
}
else {
def rep = [ respence: "0" ] // not save
render rep as JSON
}
}
我还没有找到行的解决方案:在“savebook” bookInstance.author_id = json.author_id
由作者创造了一本书。
我的第二个问题是应该如何构建REST POST的JSON对象的结构?
非常感谢你非常非常! –