在下面的代码中,我正在构建具有作者和标题的 Book.groovy json ..我的问题来自 Book.groovy 如何删除商店字段..我尝试了以下方法,在渲染后我仍然在我的 json 响应中看到商店

 def book_custom_list(Integer max) { 
    println "In book_custom_list" 
    book_instance.authors.titles.remove('stores') 
    book_instance.each { e -> 
        println e.authors.titles 
 
    } 
    render ....... 
} 
Domain Controllers
Book.groovy
class Book { 
String name 
 
static hasMany = [authors: Author] 
 
static constraints = { 
} 
 
@Override 
public String toString() { 
    name 
} 
} 

作者.groovy
class Author { 
String name; 
 
static hasMany = [titles : Title] 
static constraints = { 
    titles cascade: "all-delete-orphan" 
} 
} 

标题.groovy
class Title { 
 
Stores stores 
Date dateCreated 
 
 
 } 

JSON:
{ 
"id": 1, 
"name": "test", 
"authors": [ 
  { 
    "id": 1, 
    "name": "sdsd", 
    "titles": [ 
      { 
        "id": 7, 
        "stores": { 
          "id": 8, 
         } 
          "dateCreated": "Sep 25, 2013 12:50:42 PM", 
      } 
      ] 
   }] 
   } 

请您参考如下方法:

如果您只想始终包含特定属性,那么您真的想使用 ObjectMarshaller 接口(interface)。见 this article
更多细节。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!