From 0ab3cfd4c78a473de353ae50c2ceb99be722b171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 3 Jun 2025 21:55:00 +0800 Subject: [PATCH] fix --- src/main/java/cn/zhangdeman/HashMapCache.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/cn/zhangdeman/HashMapCache.java b/src/main/java/cn/zhangdeman/HashMapCache.java index 672b824..e2ba6a5 100644 --- a/src/main/java/cn/zhangdeman/HashMapCache.java +++ b/src/main/java/cn/zhangdeman/HashMapCache.java @@ -54,7 +54,7 @@ public class HashMapCache implements ServletContextListener { ICustomExceptionAnnotation iCustomExceptionAnnotation = (ICustomExceptionAnnotation) (constructor.newInstance()); List list = iCustomExceptionAnnotation.list(); for (ICustomExceptionConfig iCustomExceptionConfig: list) { - cache.put(iCustomExceptionConfig.getCategory()+"_"+iCustomExceptionConfig.getCode(), iCustomExceptionConfig); + getInstance().cache.put(iCustomExceptionConfig.getCategory()+"_"+iCustomExceptionConfig.getCode(), iCustomExceptionConfig); } } else { // 是枚举类 @@ -62,7 +62,7 @@ public class HashMapCache implements ServletContextListener { Object[] objectList = (Object[]) method.invoke(null); for (Object itemEnumObject: objectList) { ICustomExceptionConfig iCustomExceptionConfig = (ICustomExceptionConfig)itemEnumObject; - cache.put(iCustomExceptionConfig.getCategory()+"_"+iCustomExceptionConfig.getCode(), iCustomExceptionConfig); + getInstance().cache.put(iCustomExceptionConfig.getCategory()+"_"+iCustomExceptionConfig.getCode(), iCustomExceptionConfig); } } } @@ -76,24 +76,24 @@ public class HashMapCache implements ServletContextListener { // 读取描述 public String getMessage(String category, String code) { String key = category + "_" + code; - if (!cache.containsKey(key)) { + if (!getInstance().cache.containsKey(key)) { // 不包含指定code return key; } - return cache.get(key).getMessage(); + return getInstance().cache.get(key).getMessage(); } // 添加 public void put(String category, String code, String message) { String key = category + "_" + code; - cache.put(key, new CustomExceptionConfig(category, code, message)); + getInstance().cache.put(key, new CustomExceptionConfig(category, code, message)); } // 直接添加异常实例 public void putByConfig(ICustomExceptionConfig iCustomExceptionConfig) { String key = iCustomExceptionConfig.getCategory() + "_" + iCustomExceptionConfig.getCode(); - cache.put(key, iCustomExceptionConfig); + getInstance().cache.put(key, iCustomExceptionConfig); } // 获取一个包下的所有类列表