BootStrap.groovy内容不会更新内容

时间:2013-04-18 16:10:40

标签: grails bootstrapping

我是Grails的新手,并通过InfoQ的“Grails入门”一书进行研究。 通过它我遇到了BootStrap.groovy文件的问题:

  1. 我按照书中的说法对其进行了编辑。
  2. 运行应用程序 - 已经显示我输入BootStrap.groovy的数据。
  3. 我已更新自举值,但不会更改。 控制台中没有显示错误。
  4. 我尝试了什么:

    • 交换def的地方;
    • 将Runner的类值设置为nullables;
    • 将.save(failOnError:true)更改为.save(flush:true)。

    即使在我更改了Race类的bootstrapping值后,它看起来还没有被更改。

    看起来该值取自BootStrap.groovy以外的其他地方?

    我将Grails 2.2.1与PostgreSQL DB一起使用。 课程代码如下:

    package racetrack
    
    class Runner {
        static constraints = {
            firstName(blank:false)
            lastName(blank:false)
            dateOfBirth(nullable:true)
            gender(inList:["M","F"])
            address(nullable:true)
            city(nullable:true)
            state(nullable:true)
            zipcode(nullable:true)
            email(email:true)
        }
    
        static hasMany = [registrations:Registration]
    
        /*static mapping = {
            sort "email"
        }*/
    
        String firstName
        String lastName
        Date dateOfBirth
        String gender
        String address
        String city
        String state
        String zipcode
        String email
    
        String toString(){
            "${firstName} ${lastName} (${email})"
        }
    }
    

    package racetrack
    
    class BootStrap {
        def init = { servletContext ->
            def begun = new Runner(firstName:"Marathon",
                lastName:"Runner",
                dateOfBirth:"",
                gender:"M",
                address:"",
            city:"",
                state:"",
                zipcode:"",
                email:"me@me.ru"
                )
            begun.save(flush:true)
    
            def zabeg = new Race(name:"Run SPB",
                startDate:new Date() + 360*30,
                city:"Moscow",
                state:"Moscow",
                cost:10.0,
                distance:42.0,
                maxRunners:10)
            zabeg.save(flush:true)
        }
    
        def destroy = {
        }
    }
    
    编辑:由于运行了generate-*个脚本,可能会发生这种情况吗?

    Race.groovy:

    package racetrack
    
    class Race {
        static hasMany = [registrations:Registration]
    
        String name
        Date startDate
        String city
        String state
        BigDecimal distance
        BigDecimal cost
        Integer maxRunners
    
        static constraints = {
            name(blank:false, maxSize:50)
            startDate(validator: {
                    return (it >= new Date())
                }
            )
            city()
            state(inList:["Moscow", "Volgograd", "SPb", "NN"])
            distance(min:0.0)
            cost(min:0.0, max:100.0)
            maxRunners(min:0, max:100000)
        }
    
        static mapping = {
            sort "startDate"
        }
    
        BigDecimal inMiles(){
            return distance*0.6214
        }
    
        String toString(){
            return "${name}, ${startDate.format('MM/dd/yyyy')}"
        }
    }
    

3 个答案:

答案 0 :(得分:0)

BootStrap应该在grails-app/conf中。请参阅this

答案 1 :(得分:0)

尝试通过添加

来打印您保存的新实例的错误
print begun.errors

看看是否出现了一些事情。

答案 2 :(得分:0)

您需要删除

def index() { }

来自控制器。

我有同样的问题。现在它已修复。

相关问题