mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
This commit is contained in:
parent
e8f0910049
commit
ed0af0f42c
@ -86,7 +86,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
if (ew instanceof MPJLambdaWrapper) {
|
||||
MPJLambdaWrapper wrapper = (MPJLambdaWrapper) ew;
|
||||
if (wrapper.getEntityClass() == null) {
|
||||
wrapper.setEntityClass(MPJTableMapperHelper.getEntity(getEntity(ms.getId())));
|
||||
wrapper.setEntityClass(MPJTableMapperHelper.getEntity(getEntity(ms.getId(), ms.getResource())));
|
||||
}
|
||||
if (wrapper.getSelectColumns().isEmpty() && wrapper.getEntityClass() != null) {
|
||||
wrapper.selectAll(wrapper.getEntityClass());
|
||||
@ -359,12 +359,30 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getEntity(String id) {
|
||||
private Class<?> getEntity(String id, String resource) {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
return Class.forName(id.substring(0, id.lastIndexOf(StringPool.DOT)));
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
String className = id.substring(0, id.lastIndexOf(StringPool.DOT));
|
||||
try {
|
||||
clazz = Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
clazz = MPJTableMapperHelper.getMapperForName(className);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (Objects.nonNull(clazz)) {
|
||||
return clazz;
|
||||
}
|
||||
try {
|
||||
String className = resource.substring(0, id.lastIndexOf(StringPool.DOT)).replaceAll("/",StringPool.DOT);
|
||||
try {
|
||||
clazz = Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
clazz = MPJTableMapperHelper.getMapperForName(className);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private String removeDot(String str) {
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@ -13,21 +16,29 @@ public class MPJTableMapperHelper {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, Class<?>> CACHE_REVERSE = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Class<?>> CACHE_MAPPER = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static void init(Class<?> clazz, Class<?> mapper) {
|
||||
if (clazz != null && mapper != null) {
|
||||
CACHE.put(clazz, mapper);
|
||||
CACHE_REVERSE.put(mapper, clazz);
|
||||
CACHE_MAPPER.put(mapper.getName(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getMapper(Class<?> clazz) {
|
||||
return CACHE.get(clazz);
|
||||
return Optional.ofNullable(clazz).map(m -> CACHE.get(clazz)).orElse(null);
|
||||
}
|
||||
|
||||
public static Class<?> getEntity(Class<?> clazz) {
|
||||
return CACHE_REVERSE.get(clazz);
|
||||
return Optional.ofNullable(clazz).map(m -> CACHE_REVERSE.get(clazz)).orElse(null);
|
||||
}
|
||||
|
||||
public static Class<?> getMapperForName(String name) {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return null;
|
||||
}
|
||||
return CACHE_MAPPER.get(name);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user