我有一个实体,其中包含一个枚举类型的属性:
// MyFile.java
public class MyFile {
private DownloadStatus downloadStatus;
// other properties, setters and getters
}
// DownloadStatus.java
public enum DownloadStatus {
NOT_DOWNLOADED(1),
DOWNLOAD_IN_PROGRESS(2),
DOWNLOADED(3);
private int value;
private DownloadStatus(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
我想将这个实体保存在数据库中并检索它。问题是,我将int值保存在数据库中,而我得到的是int值!我不能像下面这样使用switch:
MyFile file = new MyFile();
int downloadStatus = ...
switch(downloadStatus) {
case NOT_DOWNLOADED:
file.setDownloadStatus(NOT_DOWNLOADED);
break;
// ...
}
我该怎么办?