填充Grails域类

填充Grails域类,grails,groovy,Grails,Groovy,我编写了一个填充Grail域类的简单代码和一个显示db内容的代码,但它不起作用。附件是我的代码!谢谢你的帮助 def populateDB(int nofelements) { def instance for (int i=1;i<=nofelements;i++){ instance=new Avendpoint() instance.avName=org.apache.commons.lang.R

我编写了一个填充Grail域类的简单代码和一个显示db内容的代码,但它不起作用。附件是我的代码!谢谢你的帮助

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
    }
def填充B(整数)
{
def实例

对于(int i=1;i第一件事是尝试使用:
instance.save(flush:true,failOnError:true)
。默认情况下,Grails不会在域没有它的字段约束时抛出异常。可能实例在验证时被拒绝,不会被保存。

叹气……什么是“它不工作”意思是?有错误吗?它会做什么?抛出错误吗?Grails的哪个版本?您如何调用
populateDB
——通常的做法是检查BootStrap.groovy中是否处于开发模式,并在那里插入数据(如果是)。此外,请尝试
instance.save(failOnError:true,flush:true)
因为这可能是一个验证问题?不,没有错误,但数据库中没有任何内容!您正在调用
populateDB
?从哪里来?您发布的代码位于哪里?它是什么类型的Grails“工件”?