GORM domain class properties default values

丶灬走出姿态 提交于 2019-12-21 03:31:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!