Grails 域对象包括类属性

标签 grails grails-orm grails-domain-class

我正在使用域对象与 Grails 中的数据库进行交互。

当我在域对象上使用 list() 方法从数据库中获取所有行时,它工作得很好,除了一件事。每行返回的对象还包括一个名为“类”的属性。我已经阅读了一些有关创建自定义编码器的内容,该编码器允许我从对象中删除该属性。这真的是不必返回类属性的最佳方法吗?

谢谢!

最佳答案

您也可以使用 JSON.registerObjectMarshaller 如下:

// BootStrap.groovy
JSON.registerObjectMarshaller( YourDomain ) {
    it.properties.findAll { it.name != 'class' }
}

引用 here对于一个类似的例子。

关于Grails 域对象包括类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27870010/

相关文章:

sql - 如何在 Grails/GORM 中将派生属性设置为小写?

grails - 使字段基于 bool 字段值且在grails域中具有多个列,使字段唯一

grails - 为什么用户使用 Spring Security 和 Grails 进行更新而不调用 save()?

grails - 过滤 'belongsTo'结果

java - Grails 2.4.5 依赖项解析错误

hibernate - hibernate 过滤器不适用于父域

grails - 在Grails中映射两个域类

grails - 如何从一对多关系的数组列表中查找

java - grails 域而不保存它

hibernate - 从 Hibernate 3/Grails 2.2.4 迁移到 Hiberate 5/Grails 3.2.4 时出现 MappingException