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
d40c0d46d0
commit
a500230a6b
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||||
|
import org.apache.ibatis.type.SimpleTypeRegistry;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -36,32 +37,34 @@ public class TableHelper {
|
|||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public static TableInfo get(Class<?> clazz) {
|
public static TableInfo get(Class<?> clazz) {
|
||||||
if (Objects.nonNull(clazz)) {
|
if (clazz == null || clazz.isPrimitive() || SimpleTypeRegistry.isSimpleType(clazz) || clazz.isInterface()) {
|
||||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
|
||||||
if (Objects.nonNull(tableInfo)) {
|
|
||||||
return tableInfo;
|
|
||||||
}
|
|
||||||
TableInfo info = TABLE_INFO_CACHE.get(clazz);
|
|
||||||
//尝试获取父类缓存
|
|
||||||
Class<?> currentClass = clazz;
|
|
||||||
while (Object.class != currentClass) {
|
|
||||||
currentClass = currentClass.getSuperclass();
|
|
||||||
info = TABLE_INFO_CACHE.get(ClassUtils.getUserClass(currentClass));
|
|
||||||
}
|
|
||||||
if (Objects.nonNull(info)) {
|
|
||||||
TABLE_INFO_CACHE.put(currentClass, info);
|
|
||||||
} else {
|
|
||||||
if (!load) {
|
|
||||||
SpringContentUtils.getBean(MPJInterceptorConfig.class);
|
|
||||||
SpringContentUtils.getBeansOfType(BaseMapper.class);
|
|
||||||
load = true;
|
|
||||||
return get(clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
||||||
|
if (Objects.nonNull(tableInfo)) {
|
||||||
|
return tableInfo;
|
||||||
|
}
|
||||||
|
TableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||||
|
if (null != info) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
//尝试获取父类缓存
|
||||||
|
Class<?> currentClass = clazz;
|
||||||
|
while (Object.class != currentClass) {
|
||||||
|
currentClass = currentClass.getSuperclass();
|
||||||
|
info = TABLE_INFO_CACHE.get(ClassUtils.getUserClass(currentClass));
|
||||||
|
}
|
||||||
|
if (Objects.nonNull(info)) {
|
||||||
|
TABLE_INFO_CACHE.put(currentClass, info);
|
||||||
|
} else {
|
||||||
|
if (!load) {
|
||||||
|
SpringContentUtils.getBean(MPJInterceptorConfig.class);
|
||||||
|
SpringContentUtils.getBeansOfType(BaseMapper.class);
|
||||||
|
load = true;
|
||||||
|
return get(clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TableInfo getAssert(Class<?> clazz) {
|
public static TableInfo getAssert(Class<?> clazz) {
|
||||||
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.OrderBy;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
@ -345,8 +344,7 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
|||||||
for (Children wrapper : onWrappers) {
|
for (Children wrapper : onWrappers) {
|
||||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||||
TableInfo tableInfo = TableHelper.get(wrapper.getJoinClass());
|
TableInfo tableInfo = TableHelper.getAssert(wrapper.getJoinClass());
|
||||||
Assert.notNull(tableInfo, "not find tableInfo by class %s", wrapper.getJoinClass().getName());
|
|
||||||
if (ConfigProperties.tableInfoAdapter.mpjHasLogic(tableInfo)) {
|
if (ConfigProperties.tableInfoAdapter.mpjHasLogic(tableInfo)) {
|
||||||
wrapper.appendSqlSegments(APPLY, () -> LogicInfoUtils.getLogicInfoNoAnd(
|
wrapper.appendSqlSegments(APPLY, () -> LogicInfoUtils.getLogicInfoNoAnd(
|
||||||
wrapper.getIndex(), wrapper.getJoinClass(), wrapper.isHasAlias(), wrapper.getAlias()
|
wrapper.getIndex(), wrapper.getJoinClass(), wrapper.isHasAlias(), wrapper.getAlias()
|
||||||
|
@ -6,6 +6,8 @@ import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
|||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关系映射配置
|
* 关系映射配置
|
||||||
*
|
*
|
||||||
@ -16,7 +18,8 @@ import lombok.NoArgsConstructor;
|
|||||||
public class MappingConfig {
|
public class MappingConfig {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
TableInfoHelper.getTableInfos().forEach(i ->
|
TableInfoHelper.getTableInfos().stream().filter(f ->
|
||||||
|
Objects.nonNull(TableInfoHelper.getTableInfo(f.getEntityType()))).forEach(i ->
|
||||||
MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.getMapper(i.getEntityType())));
|
MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.getMapper(i.getEntityType())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,7 @@ public class MPJTableFieldInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initBindField(String bindName) {
|
private void initBindField(String bindName) {
|
||||||
TableInfo info = TableHelper.get(this.joinClass);
|
TableInfo info = TableHelper.getAssert(this.joinClass);
|
||||||
Assert.notNull(info, "未注册的实体类 <%s>", this.joinClass.getSimpleName());
|
|
||||||
//根据属性名查询
|
//根据属性名查询
|
||||||
Field field = info.getFieldList().stream().filter(i -> i.getProperty().equals(bindName))
|
Field field = info.getFieldList().stream().filter(i -> i.getProperty().equals(bindName))
|
||||||
.findFirst().map(f -> getField(this.joinClass, f)).orElse(null);
|
.findFirst().map(f -> getField(this.joinClass, f)).orElse(null);
|
||||||
@ -304,11 +303,7 @@ public class MPJTableFieldInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TableInfo getTableInfo(Class<?> clazz) {
|
private TableInfo getTableInfo(Class<?> clazz) {
|
||||||
TableInfo tableInfo = TableHelper.get(clazz);
|
return TableHelper.getAssert(clazz);
|
||||||
if (tableInfo == null) {
|
|
||||||
throw ExceptionUtils.mpe("未注册 mapper " + clazz.getName());
|
|
||||||
}
|
|
||||||
return tableInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(Class<?> table, TableFieldInfo tableFieldInfo) {
|
private Field getField(Class<?> table, TableFieldInfo tableFieldInfo) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user