我想創建一個新的Project實例(代碼在下面給出),但是這些約束不允許我這樣做,因爲不是看到名字,項目生成ID的。例如,而不是'目標'(名稱)它會得到'3'('目標'名稱的ID)。我的同事告訴我創建一個服務,它將返回基於id的屬性的實際名稱,並從ProjectController調用該服務。我不熟悉Groovy和Grails的語法,所以我不知道該怎麼做。提取對象的實際值,知道它的ID在Grails中
我有一個具有name屬性的Stage域類。在我的Bootstrap中,我爲階段加載了不同的名字。
if (Stage.count() == 0) {
new Stage(name: "").save()
new Stage(name: "Not Started").save()
new Stage(name: "On target").save()
new Stage(name: "Off target").save()
new Stage(name: "Late").save()
new Stage(name: "Critically Late").save()
new Stage(name: "Complete").save()
}
我也有一個具有舞臺屬性的工程類,我應用了一些約束,這些階段:
class Project {
String name
Date dueDate
Date startDate
Stage requirements
Stage design
Stage development
Stage qa
Stage ua
Stage delivery
Date deliveryDue
static constraints = {
name blank: false, unique: true
dueDate min: new Date() - 1, max: new Date() + 365 * 10
startDate min: new Date() - 1, max: new Date() + 365 * 10
requirements inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
design inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
development inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
qa inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
ua inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
delivery inList: ["Not started", "Critically Late", "Off Target Date", "On target"]
}
}
顯示代碼,你實際上試圖創建它, –