From 80a42d32ea7853ebe0f64b62f3534b792865bc98 Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Mon, 4 Aug 2025 19:51:05 +0800 Subject: [PATCH] feat(core): ContentTypeEnum --- .../common/core/enums/ContentTypeEnum.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/ContentTypeEnum.java diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/ContentTypeEnum.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/ContentTypeEnum.java new file mode 100644 index 00000000..78530307 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/ContentTypeEnum.java @@ -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; + } +}