问题描述
也许一个愚蠢的问题,但我应该在哪里/如何定义GORM域类属性的默认值?例如,当我创建一个新的公司对象实例时,我希望属性国家的默认值为美国。我想我可以在创建控制器中执行它,但看起来有点肮脏。例如:
def create = {
def companyInstance = new Company()
companyInstance.properties = params
companyInstance.accepted =USA
...
将它放入域类本身中
class Company {
String country =USA
}
Maybe a silly question but where/how should I define default values for GORM domain class properties? For example when I'm creating a new Company object instance I want default value for property country to be "USA". I guess I could do it in create controller but it looks kinda dirty. Something like:
def create = { def companyInstance = new Company() companyInstance.properties = params companyInstance.accepted = "USA" ...
Put it in the domain class itself
class Company {
String country = "USA"
}
这篇关于GORM域类属性默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!