domain对象
class Company { String name Integer numberOfEmployees BigDecimal salaryPaidYTD static transients = ['salaryPaidYTD'] }
salaryPaidYTD属性为瞬时属性,内容不会被保存到数据库
还可以用get***方式处理瞬时属性,如下
class Company { BigDecimal cash BigDecimal receivables BigDecimal capital BigDecimal getNetWorth() { cash + receivables + capital } static transients = ['netWorth'] }
此时的netWorth属性声明为瞬时属性
还可以用派生属性的方式声明瞬时属性,如下
class Company { BigDecimal cash BigDecimal receivables BigDecimal capital BigDecimal netWorth static mapping = { netWorth formula: 'CASH + RECEIVABLES + CAPITAL' } }