public enum ImageFormatType {
/**
* jpg
*/
JPG(0, "jpg"),
/**
* png
*/
PNG(1, "png"),
/**
* webp
*/
WEBP(2, "webp"),
/**
* bmp
*/
BMP(3, "bmp"),
/**
* gif
*/
GIF(4, "gif"),
/**
* tiff
*/
TIFF(5, "tiff"),
;
private Integer code;
private String value;
ImageFormatType(Integer code, String value) {
this.code = code;
this.value = value;
}
public static Integer getCode(Integer code) {
ImageFormatType[] imageFormatTypes = values();
for (ImageFormatType imageFormatType : imageFormatTypes) {
if (imageFormatType.code().equals(code)) {
return imageFormatType.code();
}
}
return null;
}
public static String getValue(Integer code) {
ImageFormatType[] imageFormatTypes = values();
for (ImageFormatType imageFormatType : imageFormatTypes) {
if (imageFormatType.code().equals(code)) {
return imageFormatType.value();
}
}
return null;
}
public Integer code() {
return code;
}
public String value() {
return value;
}
}
java枚举类型根据key拿到value
最新推荐文章于 2025-05-19 18:16:21 发布