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

前端之家收集整理的这篇文章主要介绍了如何在Grails 2.2中为Domain Class Values设置默认值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的Grails域类中,我想设置在数据库中保留的默认值.我使用 mysql作为数据库.我试着这样做:
  1. class A {
  2.  
  3. long someValue = 1
  4. long someOtherValue
  5. boolean someBool = true
  6. boolean someOtherBool
  7.  
  8. static mapping = {
  9. someOtherValue defaultValue: 1
  10. someOtherBool defaultValue: true
  11. }
  12. }

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

解决方法

如果您使用的是上面的Grails 2.2,那么您可以使用defaultValue.看看伯特的答案 here
尝试一下,希望这会有所帮助:
  1. Class A {
  2. Long someValue
  3. Long someOtherValue
  4.  
  5. Boolean someBool
  6. Boolean someOtherBool
  7.  
  8. static mapping = {
  9. someOtherValue defaultValue: 1
  10. someOtherBool defaultValue: true
  11. ...
  12. }
  13.  
  14. }

猜你在找的HTML相关文章