2015-10-07 49 views
0

文件夾結構: HRMS如何使用瞬態值域類Grails的2.4.4

Domain 
    com.hrms.ei.employeeinfo 
Controllers 
    com.hrms.ei.employeeinformation.controller 
Views 
    employeeinformation 
     edit.gsp 
     list.gsp 
     show.gsp 

我有DATE_OF_BIRTH這是從普惠制--->控制器--->域傳遞和使用的列在employeeinfo.groovy(域)中進行驗證。但我不想在employeeinfo表中創建date_of_birth的列,所以我使用了static transients = ['date_of_birth']。我在域類中聲明該列爲Date date_of_birth

雖然使用static transients = ['date_of_birth']它返回null,但如果我從域類中刪除static transients,該列將在DB中創建。 Grails 1.3.7中也有相同的邏輯。

回答

1

我認爲你需要爲約束節中的屬性添加可綁定。 http://grails.github.io/grails-doc/latest/ref/Constraints/bindable.html

+0

嗨......這些都是域類的靜態約束中所給代碼= { DATE_OF_BIRTH綁定:假 } 靜態瞬變= [「DATE_OF_BIRTH」] 日期DATE_OF_BIRTH,但它不工作..但仍然是返回null ... – Nojesh

+0

如果它的日期字段,然後參數將有不同的綁定,您可以檢查http://www.tothenew.com/blog/new-data-binding-features-in-grails-2-3/和g:datePicker代碼,它爲日期綁定提供了_year月份字段 http://grails.github.io/grails-doc/latest/ref/Tags/datePicker.html – Uday

+0

謝謝你,夥計......它的工作現在.. .i將代碼更改爲date_of_birth可綁定:true,可爲空:假 – Nojesh