问题
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"
}
来源:https://stackoverflow.com/questions/8256627/gorm-domain-class-properties-default-values