java - 要存储在数据库中的枚举

标签 java android database enums

我有一个像这样的枚举类 -

public enum FeedbackStatus {
    @JsonProperty("unprocessed")
    UNPROCESSED("unprocessed"),

    @JsonProperty("arrived")
    ARRIVED("arrived"),

    @JsonProperty("performed")
    PERFORMED("performed"),

    @JsonProperty("cancelled")
    CANCELLED("cancelled"),

    @JsonProperty("removed")
    REMOVED("removed"),

    @JsonProperty("no-show")
    NO_SHOW("no-show"),

    @JsonProperty("cancel-at-door")
    CANCEL_AT_DOOR("cancel-at-door");

    private static final FeedbackStatus[] myEnumValues = FeedbackStatus.values();
    private final String fieldDescription;

    private FeedbackStatus(String value) {
        this.fieldDescription = value;
    }

    public static FeedbackStatus fromString(String string) {
        if (!TextUtils.isEmpty(string)) {
            for (FeedbackStatus feedbackStatus : myEnumValues) {
                if (feedbackStatus.getString().equalsIgnoreCase(string)) {
                    return feedbackStatus;
                }
            }
        }
        throw new IllegalArgumentException("No constant with text " + string + " found");
    }

    public String getString() {
        return this.fieldDescription;
    }
}

我需要使用 GreneDAO 在 SQLITE 数据库中存储一个对象 feedback 但该对象是一个枚举,因此我无法存储它。对象就像 -

private FeedbackStatus feedback;

如何将其存储为字符串?

最佳答案

用于前。已取消。值?什么时候存储数据?还有 ENUM.toString()。您可以将其存储为 String,然后使用 String to Enum 方法将恢复数据包装起来。

关于java - 要存储在数据库中的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39168939/

相关文章:

java - 表格打印不适合页面尺寸

mysql - 根据mysql中的另一列从列中检索数据

sql - PostgreSQL 中的自定义聚合函数

java - 为什么 Selenium 测试网站不能在多个页面上运行?

java - Espresso - 如何检查是否显示其中一个 View

android:验证 Intent 发送者的身份

Android KSoap2 : how to get property name

java - 需要帮助将简短的 Objective-C 例程转换为 Java

java - 3DES 加密/解密在 Windows 中有效,在 Linux 中抛出 IllegalBlockSizeException

Android JobInfo builder periodiy daily