微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Grails 2.2中为Domain Class Values设置默认值?

在我的Grails域类中,我想设置在数据库中保留的认值.我使用 mysql作为数据库.我试着这样做:
class A {

   long someValue = 1
   long someOtherValue
   boolean someBool = true
   boolean someOtherBool

   static mapping = {
      someOtherValue defaultValue: 1
      someOtherBool defaultValue: true  
   }
}

但没有任何作用.数据库中没有设置认值.我需要更改什么才能正确设置认值?

解决方法

如果您使用的是上面的Grails 2.2,那么您可以使用defaultValue.看看伯特的答案 here
尝试一下,希望这会有所帮助:
Class A {
      Long someValue 
      Long someOtherValue

      Boolean someBool
      Boolean someOtherBool

     static mapping = {
        someOtherValue defaultValue: 1
        someOtherBool  defaultValue: true  
        ...
     } 

}

原文地址:https://www.jb51.cc/html/223969.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐