小编goo*_*ara的帖子

Grails字符串枚举?

假设我有这个枚举:

public enum MyEnum {
    AUSTRALIA_SYDNEY ("Australia/Sydney"),
    AUSTRALIA_ADELAIDE ("Australia/Adelaide"),

    private String name

    private Timezone(String name){
        this.name = name
    }

    public String value() {
        name
    }

    String toString() {
        name
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让我使用其值/名称获取枚举?现在,我正在尝试这样做,但它不起作用:

MyEnum.valueOf("Australia/Sydney")
Run Code Online (Sandbox Code Playgroud)

What I'm getting from the DB is a string (in this case: "Australia/Sydney"), and not the value, and unfortunately, I can't just alter the type it returns because its an old system and I'm just connecting to this DB that is shared by multiple apps. Anyway around …

grails groovy

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

grails ×1

groovy ×1