feat(core): ContentTypeEnum
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
00be7b4c47
commit
80a42d32ea
@ -0,0 +1,70 @@
|
||||
package org.dromara.common.core.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
* @apiNote ContentTypeEnum
|
||||
* @since 2025/8/4
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ContentTypeEnum {
|
||||
|
||||
/**
|
||||
* JPEG图片类型
|
||||
*/
|
||||
JPG("jpg", "image/jpeg"),
|
||||
|
||||
/**
|
||||
* JPEG图片类型
|
||||
*/
|
||||
JPEG("jpeg", "image/jpeg"),
|
||||
|
||||
/**
|
||||
* PNG图片类型
|
||||
*/
|
||||
PNG("png", "image/png"),
|
||||
|
||||
/**
|
||||
* GIF图片类型
|
||||
*/
|
||||
GIF("gif", "image/gif");
|
||||
|
||||
private final String extension;
|
||||
private final String contentType;
|
||||
|
||||
/**
|
||||
* 根据文件扩展名获取内容类型
|
||||
*
|
||||
* @param extension 文件扩展名
|
||||
* @return 对应的内容类型,如果未找到则返回null
|
||||
*/
|
||||
public static String getContentType(String extension) {
|
||||
for (ContentTypeEnum type : values()) {
|
||||
if (type.extension.equalsIgnoreCase(extension)) {
|
||||
return type.contentType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件扩展名
|
||||
*
|
||||
* @return 文件扩展名
|
||||
*/
|
||||
public String getExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容类型
|
||||
*
|
||||
* @return 内容类型
|
||||
*/
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user