【问题标题】:What does actually do static mapWith="mongo"?static mapWith="mongo" 实际上做了什么?
【发布时间】:2016-04-22 05:29:12
【问题描述】:

static mapWith = "mongo"

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

ma​​pWith

目的

mapWith 静态属性增加了控制域的能力 类被持久化。

示例

class Airport {
  static mapWith = "none"

}

我也经历过这个问题 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

【问题讨论】:

    标签: mongodb grails


    【解决方案1】:

    在 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!

    【讨论】:

    • 自 2021 年起链接已断开
    【解决方案2】:

    我同意@Mananpreet Singh 的回答,但是对于static mapWith = "mongo" 特别要明确的是,这意味着如果你想用 Mongo 而不是 Hibernate 来持久化一个特定的域类,你必须使用它。

    http://gorm.grails.org/latest/mongodb/manual/#withHibernate

    【讨论】:

      猜你喜欢
      • 2013-06-02
      • 2020-11-21
      • 2015-02-26
      • 2017-06-29
      • 2013-06-13
      • 2021-10-25
      • 2011-08-12
      • 1970-01-01
      • 2010-11-27
      相关资源
      最近更新 更多