枚举类不能转换为java.lang.String(Grails)

时间:2017-04-19 08:18:23

标签: grails enums

我对grails和制作迷你项目都很陌生。 Grails版本2.4.5。我有一个租赁类,状态为枚举。我知道我必须在/ src / groovy中创建一个类。

package ers

enum EquipmentStatusEnum {
    Available ("Available"),
    Rented ("Rented")

    String name

    EquipmentStatusEnum(String name) {
        this.name = name
    }
}

域名类租赁

package ers

class Rental implements Serializable {

    Date dateRented

    EquipmentStatusEnum status

    ClientAccount account
    Equipment equipment

    static constraints = {
        status shared:"gc", inList: EquipmentStatusEnum.values()*.name
    }

    static mapping = {
        id composite:['account', 'equipment']
    }
}

考虑到这一点,我正在尝试在Bootstrap.groovy中填充我的数据库表

new Rental(account:ClientAccountInstance1, equipment:EquipmentInstance1, dateRented: new Date("April 7, 2017"), status:'Available').save(failOnError:true, flush:true)
new Rental(account:ClientAccountInstance2, equipment:EquipmentInstance3, dateRented: new Date("April 8, 2017"), status:'Available').save(failOnError:true, flush:true)
new Rental(account:ClientAccountInstance3, equipment:EquipmentInstance5, dateRented: new Date("April 9, 2017"), status:'Available').save(failOnError:true, flush:true)

但在运行我的应用程序之后。发生错误说:

| Error 2017-04-19 16:02:29,589 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: ers.EquipmentStatusEnum cannot be cast to java.lang.String
Message: ers.EquipmentStatusEnum cannot be cast to java.lang.String

似乎有什么问题?非常感谢所有帮助。

0 个答案:

没有答案