gpt4 book ai didi

grails - BootStrap.groovy内容不会更新内容

转载 作者:行者123 更新时间:2023-12-02 14:53:35 27 4
gpt4 key购买 nike

我是Grails的新手,可以通过InfoQ的“Grails入门”一书来学习它。
通过它运行,我遇到了BootStrap.groovy文件的问题:

  • 我已经按照书中所述对其进行了编辑。
  • 运行它-并显示了我输入到BootStrap.groovy中的数据。
  • 我已经更新了引导值,但是它们没有改变。
    控制台中未显示任何错误。

  • 我尝试过的
  • 交换def的位置;
  • 将Runner的类值设置为可为空;
  • 将.save(failOnError:true)更改为.save(flush:true)。

  • 即使更改了Race类的自举值,它似乎也没有更改。

    看起来值是从BootStrap.groovy之外的其他地方获取的?

    我将Grails 2.2.1与PostgreSQL数据库一起使用。
    该类的代码如下:
    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')}"
    }
    }

    最佳答案

    BootStrap应该改为grails-app/conf。请参阅this

    关于grails - BootStrap.groovy内容不会更新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16087991/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com