mongodb - static mapWith ="mongo"实际上做了什么?

标签 mongodb grails

static mapWith = "mongo"

我完全不清楚这是什么意思。根据http://grails.github.io/grails-doc/3.0.x/ref/Domain%20Classes/mapWith.html

ma​​pWith

Purpose

The mapWith static property adds the ability to control if a domain class is being persisted.

Examples

class Airport {
  static mapWith = "none"

}

I also went through this question Remove simpledb mapWith by meta programming in dev mode

我在我的 grails 应用程序中得到一个想法,

static mapWith = "mongo"

可能正在使用 mongoDB 插件。 但我还是不清楚。 我还浏览了这些 stackoverflow 链接:

  1. get mapWith static domain field value from GrailsDomainClass grails

  2. Is it possible in grails to disable persistence of a domain class dynamically with inheritance

  3. Migration from MongoDB to PostgreSQL Groovy Application

最佳答案

在 Grails 中,如果我们想让某些字段非持久性,我们可以像这样使用 transient 关键字:

class DomainClass {
static transients = ['field1', 'field2']
Integer field1
Integer field2
Integer persistentField1
Integer persistentField2 
}

也可以通过使用 ma​​pwith 关键字使整个领域类非持久性

class NonPersistentDomain {
.........
....................
.......................
static mapWith = 'none';
}

有人会争辩说使用命令对象而不是域更好,但它有其自身的优势:

可以使用 GrailsDomainClass 访问它。 它在通过脚手架生成 UI 时参与。

另请参阅此链接

Grails Data Mapping Mongo Manual !

关于mongodb - static mapWith ="mongo"实际上做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34831087/

相关文章:

node.js - 如何使用node js更新mongodb集合中所有文档的_id?

node.js - 如何在 Mongoose 中使用更多$group

node.js - 如何使用 Mongoose 在 mongoDB 中填充 3 个集合

Java Spring : Compatibility for both transactional and non-transactional versions of mongodb

Grails Spring Security 注册/注册用户

javascript - MEAN堆栈上的登录系统架构?

class - grails Controller 在多个域类中呈现错误

grails - 我想从一个gsp获取表单数据,并想在另一个gsp中访问该数据,并希望将该数据插入表中,我该怎么做?

grails - 我如何获得要在g:link中使用的选择框的当前选择?

security - 如何禁用 Grails createLink 编解码器(编码)?