-1
我写了一个简单的代码来填充Grail域类和用于显示数据库内容的代码,但它不起作用。附上是我的代码!我感谢任何帮助。填充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 2012-08-10 15:17:11
它有什么作用?抛出错误?什么版本的Grails?你如何调用'populateDB' - 通常的地方是检查BootStrap.groovy中的开发模式并在那里插入数据。另外,尝试'instance.save(failOnError:true,flush:true)',因为这可能是一个验证问题? – 2012-08-10 15:18:07
不,没有错误,但没有数据库在分贝! – Reza 2012-08-10 15:20:05