refactor(framework): 优化代码结构和性能

This commit is contained in:
2026-02-26 14:40:43 +08:00
parent 643a211f95
commit aa4f062026
24 changed files with 153 additions and 111 deletions
@@ -51,6 +51,7 @@ public class KitSpringBeanHolder implements ApplicationContextAware, DisposableB
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
@SuppressWarnings("all")
public static <T> T getBean(String name) {
assertContextInjected();
return (T) applicationContext.getBean(name);
@@ -261,13 +261,11 @@ public class KitRedisHelper {
return null;
}
// 如果 value 不是目标类型, 则尝试将其反序列化为 clazz 类型
if (!clazz.isInstance(value)) {
return JSON.parseObject(value.toString(), clazz);
} else if (clazz.isInstance(value)) {
boolean isInstance = clazz.isInstance(value);
if (isInstance) {
return clazz.cast(value);
} else {
return null;
}
return JSON.parseObject(value.toString(), clazz);
}
/**
@@ -631,7 +629,7 @@ public class KitRedisHelper {
public long setRemove(String key, Object... values) {
try {
Long count = redisTemplate.opsForSet().remove(key, values);
return count;
return count == null ? 0 : count;
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
@@ -87,6 +87,15 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
List<MediaType> supportMediaTypeList = new ArrayList<>();
supportMediaTypeList.add(MediaType.APPLICATION_JSON);
FastJsonConfig config = this.getFastJsonConfig();
fastJsonConverter.setFastJsonConfig(config);
fastJsonConverter.setSupportedMediaTypes(supportMediaTypeList);
fastJsonConverter.setDefaultCharset(StandardCharsets.UTF_8);
// 将 FastJsonHttpMessageConverter 添加到列表末尾
converters.add(fastJsonConverter);
}
private FastJsonConfig getFastJsonConfig() {
FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
// 开启引用检测, 枚举支持
@@ -104,11 +113,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
// config.setWriterFeatures(JSONWriter.Feature.WriteLongAsString);
config.setWriterFeatures(JSONWriter.Feature.WriteEnumUsingToString);
config.setWriterFeatures(JSONWriter.Feature.ReferenceDetection);
fastJsonConverter.setFastJsonConfig(config);
fastJsonConverter.setSupportedMediaTypes(supportMediaTypeList);
fastJsonConverter.setDefaultCharset(StandardCharsets.UTF_8);
// 将 FastJsonHttpMessageConverter 添加到列表末尾
converters.add(fastJsonConverter);
return config;
}
/**