-1
Grail 도메인 클래스를 채우기위한 간단한 코드와 db 내용을 보여주는 코드를 작성했지만 작동하지 않습니다. 첨부 된 내 코드입니다! 어떤 도움을 주셔서 감사합니다.Grails 도메인 클래스 채우기
def populateDB(int nofelements)
{
def instance
for (int i=1;i<=nofelements;i++){
instance=new Avendpoint()
instance.avName=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.bridge=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.callerID=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.con=false
instance.state=AvendpointState.ONE_WAY
instance.uid=org.apache.commons.lang.RandomStringUtils.random(5, true, true)
instance.save(flush: true)
}
render "The database has been populated successfully!"
}
def showDB(){
def instance
String res
res+=Integer.toString(Avendpoint.count())
for(int i=1; i<Avendpoint.count(); i++){
instance=Avendpoint.get(i)
res+=instance.avName+"<br>"+instance.bridge+"<br>"+instance.callerID+"<br>"+
instance.con+"<br>"+instance.state+"<br>"+instance.uid+"<br>"
}
render res
}
한숨 ... "작동하지 않습니다"는 의미는 무엇입니까? 오류가 있습니까? – hvgotcodes
그것은 무엇을합니까? 오류가 발생 했습니까? Grails의 어떤 버전입니까? 'populateDB'를 어떻게 호출하고 있습니까? 일반적인 경우 BootStrap.groovy에서 개발 모드에 있는지 확인하고 거기에 데이터를 삽입하십시오. 또한 유효성 검사 문제 일 수 있으므로'instance.save (failOnError : true, flush : true) '를 시도해보십시오. –
아니요, 오류는 없지만 db에는 아무 것도 없습니다! – Reza