【问题标题】:How to change primary key column in grails?如何更改grails中的主键列?
【发布时间】:2012-04-12 09:15:58
【问题描述】:

我有一个具有整数变量“代码”的域类。我的要求是为该域制作“代码”、主键列,并自动递增,并从为该 doamin.thnks 创建的表中删除默认的“id”列

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    使用这个:

    static mapping = {
    id name: 'code'
    }
    

    更多信息在这里: http://grails.org/doc/2.0.x/ref/Database%20Mapping/id.html

    【讨论】:

      【解决方案2】:

      默认情况下,Grails 中的域类使用合理的默认值指定它们映射到数据库的方式。您可以使用 ORM 映射 DSL 自定义这些。

      使用id 自定义域类标识符的生成方式。 请参阅Grails documentation for id

      static mapping = {
          id column: 'code', type: 'integer'
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-08-30
        • 2020-09-08
        • 1970-01-01
        • 2011-06-29
        • 2012-06-12
        • 2012-02-09
        • 2020-09-13
        相关资源
        最近更新 更多