GORM domain class properties default values

2019-03-24 11:29发布

问题:

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" ...

回答1:

Put it in the domain class itself

class Company {
    String country = "USA"
}


标签: grails gorm