This commit is contained in:
白茶清欢 2025-06-03 21:55:00 +08:00
parent 4a4e1a6a7a
commit 0ab3cfd4c7

View File

@ -54,7 +54,7 @@ public class HashMapCache implements ServletContextListener {
ICustomExceptionAnnotation iCustomExceptionAnnotation = (ICustomExceptionAnnotation) (constructor.newInstance());
List<ICustomExceptionConfig> 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);
}
// 获取一个包下的所有类列表