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
1f267b1cc2
commit
2851cd8f5b
@ -1,10 +1,9 @@
|
||||
# mybatis-plus-join
|
||||
|
||||
* 支持连表查询的 [mybatis-plus](https://gitee.com/baomidou/mybatis-plus)
|
||||
|
||||
* [演示工程](https://gitee.com/best_handsome/mybatis-plus-join-demo)
|
||||
|
||||
* 点个Star支持一下吧 :)
|
||||
* [一对一,一对多](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/MAPPING.md)
|
||||
|
||||
QQ群:1022221898
|
||||
|
||||
|
@ -3,6 +3,9 @@ package com.baomidou.mybatisplus.core.metadata;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.annotation.EntityMapping;
|
||||
import com.github.yulichang.annotation.FieldMapping;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.apache.ibatis.mapping.ResultFlag;
|
||||
@ -30,15 +33,17 @@ import static java.util.stream.Collectors.toList;
|
||||
* @author yulichang
|
||||
* @see TableInfoHelper
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MPJTableInfoHelper {
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TableInfoHelper.class);
|
||||
|
||||
|
||||
/**
|
||||
* 储存反射类表信息
|
||||
*/
|
||||
private static final Map<Class<?>, TableInfo> TABLE_INFO_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, MPJTableInfo> TABLE_INFO_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 默认表主键名称
|
||||
@ -54,13 +59,24 @@ public class MPJTableInfoHelper {
|
||||
* @param clazz 反射实体类
|
||||
* @return 数据库表反射信息
|
||||
*/
|
||||
public static TableInfo getTableInfo(Class<?> clazz) {
|
||||
public static MPJTableInfo getTableInfo(Class<?> clazz) {
|
||||
if (clazz == null || ReflectionKit.isPrimitiveOrWrapper(clazz) || clazz == String.class || clazz.isInterface()) {
|
||||
return null;
|
||||
}
|
||||
return TABLE_INFO_CACHE.get(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 获取所有实体映射表信息
|
||||
* </p>
|
||||
*
|
||||
* @return 数据库表反射信息集合
|
||||
*/
|
||||
public static List<MPJTableInfo> getTableInfos() {
|
||||
return Collections.unmodifiableList(new ArrayList<>(TABLE_INFO_CACHE.values()));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 实体类反射获取表信息【初始化】
|
||||
@ -69,13 +85,25 @@ public class MPJTableInfoHelper {
|
||||
* @param clazz 反射实体类
|
||||
* @return 数据库表反射信息
|
||||
*/
|
||||
public synchronized static TableInfo initTableInfo(Configuration configuration, String currentNamespace, Class<?> clazz) {
|
||||
TableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||
public synchronized static MPJTableInfo initTableInfo(Configuration configuration, String currentNamespace, Class<?> clazz, Class<?> mapperClass) {
|
||||
MPJTableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||
if (info != null) {
|
||||
return info;
|
||||
}
|
||||
/* 没有获取到缓存信息,则初始化 */
|
||||
TableInfo tableInfo = new TableInfo(clazz);
|
||||
MPJTableInfo mpjTableInfo = new MPJTableInfo();
|
||||
mpjTableInfo.setMapperClass(mapperClass);
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
||||
if (tableInfo != null) {
|
||||
mpjTableInfo.setTableInfo(tableInfo);
|
||||
initMapping(mpjTableInfo);
|
||||
/* 添加缓存 */
|
||||
TABLE_INFO_CACHE.put(clazz, mpjTableInfo);
|
||||
return mpjTableInfo;
|
||||
}
|
||||
|
||||
tableInfo = new TableInfo(clazz);
|
||||
mpjTableInfo.setTableInfo(tableInfo);
|
||||
tableInfo.setCurrentNamespace(currentNamespace);
|
||||
tableInfo.setConfiguration(configuration);
|
||||
GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
|
||||
@ -86,19 +114,44 @@ public class MPJTableInfoHelper {
|
||||
List<String> excludePropertyList = excludeProperty != null && excludeProperty.length > 0 ? Arrays.asList(excludeProperty) : Collections.emptyList();
|
||||
|
||||
/* 初始化字段相关 */
|
||||
initTableFields(clazz, globalConfig, tableInfo, excludePropertyList);
|
||||
initTableFields(clazz, globalConfig, mpjTableInfo, excludePropertyList);
|
||||
|
||||
/* 自动构建 resultMap */
|
||||
initResultMapIfNeed(tableInfo);
|
||||
|
||||
/* 添加缓存 */
|
||||
TABLE_INFO_CACHE.put(clazz, tableInfo);
|
||||
TABLE_INFO_CACHE.put(clazz, mpjTableInfo);
|
||||
|
||||
/* 缓存 lambda */
|
||||
LambdaUtils.installCache(tableInfo);
|
||||
return tableInfo;
|
||||
|
||||
/* 初始化映射关系 */
|
||||
initMapping(mpjTableInfo);
|
||||
return mpjTableInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 实体类反射获取表信息【初始化】
|
||||
* </p>
|
||||
*
|
||||
* @param clazz 反射实体类
|
||||
*/
|
||||
public synchronized static void initTableInfo(Class<?> clazz, Class<?> mapperClass) {
|
||||
MPJTableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||
if (info != null) {
|
||||
return;
|
||||
}
|
||||
MPJTableInfo mpjTableInfo = new MPJTableInfo();
|
||||
mpjTableInfo.setMapperClass(mapperClass);
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
||||
if (tableInfo == null) {
|
||||
return;
|
||||
}
|
||||
mpjTableInfo.setTableInfo(tableInfo);
|
||||
initMapping(mpjTableInfo);
|
||||
TABLE_INFO_CACHE.put(clazz, mpjTableInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动构建 resultMap 并注入(如果条件符合的话)
|
||||
@ -179,10 +232,6 @@ public class MPJTableInfoHelper {
|
||||
|
||||
tableInfo.setTableName(targetTableName);
|
||||
|
||||
/* 开启了自定义 KEY 生成器 */
|
||||
// if (CollectionUtils.isNotEmpty(dbConfig.getKeyGenerators())) {
|
||||
// tableInfo.setKeySequence(clazz.getAnnotation(KeySequence.class));
|
||||
// }
|
||||
return excludeProperty;
|
||||
}
|
||||
|
||||
@ -216,12 +265,12 @@ public class MPJTableInfoHelper {
|
||||
*
|
||||
* @param clazz 实体类
|
||||
* @param globalConfig 全局配置
|
||||
* @param tableInfo 数据库表反射信息
|
||||
* @param mpjTableInfo 数据库表反射信息
|
||||
*/
|
||||
private static void initTableFields(Class<?> clazz, GlobalConfig globalConfig, TableInfo tableInfo, List<String> excludeProperty) {
|
||||
private static void initTableFields(Class<?> clazz, GlobalConfig globalConfig, MPJTableInfo mpjTableInfo, List<String> excludeProperty) {
|
||||
/* 数据库全局配置 */
|
||||
GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
|
||||
ReflectorFactory reflectorFactory = tableInfo.getConfiguration().getReflectorFactory();
|
||||
ReflectorFactory reflectorFactory = mpjTableInfo.getTableInfo().getConfiguration().getReflectorFactory();
|
||||
Reflector reflector = reflectorFactory.findForClass(clazz);
|
||||
List<Field> list = getAllFields(clazz);
|
||||
// 标记是否读取到主键
|
||||
@ -244,31 +293,33 @@ public class MPJTableInfoHelper {
|
||||
if (isReadPK) {
|
||||
throw ExceptionUtils.mpe("@TableId can't more than one in Class: \"%s\".", clazz.getName());
|
||||
} else {
|
||||
initTableIdWithAnnotation(dbConfig, tableInfo, field, tableId, reflector);
|
||||
initTableIdWithAnnotation(dbConfig, mpjTableInfo.getTableInfo(), field, tableId, reflector);
|
||||
isReadPK = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (!isReadPK) {
|
||||
isReadPK = initTableIdWithoutAnnotation(dbConfig, tableInfo, field, reflector);
|
||||
isReadPK = initTableIdWithoutAnnotation(dbConfig, mpjTableInfo.getTableInfo(), field, reflector);
|
||||
if (isReadPK) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final TableField tableField = field.getAnnotation(TableField.class);
|
||||
|
||||
/* 有 @TableField 注解的字段初始化 */
|
||||
if (tableField != null) {
|
||||
fieldList.add(new TableFieldInfo(dbConfig, tableInfo, field, tableField, reflector, existTableLogic));
|
||||
fieldList.add(new TableFieldInfo(dbConfig, mpjTableInfo.getTableInfo(), field, tableField, reflector, existTableLogic));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 无 @TableField 注解的字段初始化 */
|
||||
fieldList.add(new TableFieldInfo(dbConfig, tableInfo, field, reflector, existTableLogic));
|
||||
fieldList.add(new TableFieldInfo(dbConfig, mpjTableInfo.getTableInfo(), field, reflector, existTableLogic));
|
||||
}
|
||||
|
||||
/* 字段列表 */
|
||||
tableInfo.setFieldList(fieldList);
|
||||
mpjTableInfo.getTableInfo().setFieldList(fieldList);
|
||||
|
||||
|
||||
/* 未发现主键注解,提示警告信息 */
|
||||
if (!isReadPK) {
|
||||
@ -300,6 +351,14 @@ public class MPJTableInfoHelper {
|
||||
return list.stream().anyMatch(field -> field.isAnnotationPresent(TableLogic.class));
|
||||
}
|
||||
|
||||
private static boolean isExistMapping(Class<?> clazz) {
|
||||
return ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz)).stream().anyMatch(field -> field.isAnnotationPresent(EntityMapping.class));
|
||||
}
|
||||
|
||||
private static boolean isExistMappingField(Class<?> clazz) {
|
||||
return ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz)).stream().anyMatch(field -> field.isAnnotationPresent(FieldMapping.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 主键属性初始化
|
||||
@ -430,4 +489,36 @@ public class MPJTableInfoHelper {
|
||||
return (tableField == null || tableField.exist());
|
||||
}).collect(toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化映射相关
|
||||
*/
|
||||
public static void initMapping(MPJTableInfo mpjTableInfo) {
|
||||
// 是否存在 @EntityMapping 注解
|
||||
boolean existMapping = isExistMapping(mpjTableInfo.getTableInfo().getEntityType());
|
||||
mpjTableInfo.setHasMapping(existMapping);
|
||||
// 是否存在 @FieldMapping 注解
|
||||
boolean existMappingField = isExistMappingField(mpjTableInfo.getTableInfo().getEntityType());
|
||||
mpjTableInfo.setHasMappingField(existMappingField);
|
||||
mpjTableInfo.setHasMappingOrField(existMapping || existMappingField);
|
||||
/* 关系映射初始化 */
|
||||
List<MPJTableFieldInfo> mpjFieldList = new ArrayList<>();
|
||||
List<Field> fields = ReflectionKit.getFieldList(ClassUtils.getUserClass(mpjTableInfo.getTableInfo().getEntityType()));
|
||||
for (Field field : fields) {
|
||||
if (existMapping) {
|
||||
EntityMapping mapping = field.getAnnotation(EntityMapping.class);
|
||||
if (mapping != null) {
|
||||
mpjFieldList.add(new MPJTableFieldInfo(mpjTableInfo.getTableInfo().getEntityType(), mapping, field));
|
||||
}
|
||||
}
|
||||
if (existMappingField) {
|
||||
FieldMapping mapping = field.getAnnotation(FieldMapping.class);
|
||||
if (mapping != null) {
|
||||
mpjFieldList.add(new MPJTableFieldInfo(mpjTableInfo.getTableInfo().getEntityType(), mapping, field));
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 映射字段列表 */
|
||||
mpjTableInfo.setFieldList(mpjFieldList);
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,14 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.github.yulichang.base.mapper.MPJDeepMapper;
|
||||
import com.github.yulichang.base.mapper.MPJJoinMapper;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see BaseMapper
|
||||
*/
|
||||
public interface MPJBaseMapper<T> extends BaseMapper<T> {
|
||||
public interface MPJBaseMapper<T> extends MPJJoinMapper<T>, MPJDeepMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Integer selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
* @param <DTO> 分页返回对象
|
||||
*/
|
||||
<DTO, P extends IPage<?>> IPage<DTO> selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
<P extends IPage<?>> IPage<Map<String, Object>> selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
}
|
||||
|
@ -1,50 +1,15 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.github.yulichang.base.service.MPJDeepService;
|
||||
import com.github.yulichang.base.service.MPJJoinService;
|
||||
|
||||
/**
|
||||
* 基础service
|
||||
* 目前包含两个模块 连表查询 和 关系映射
|
||||
*
|
||||
* @author yulichang
|
||||
* @see IService
|
||||
* @see MPJJoinService
|
||||
* @see MPJDeepService
|
||||
*/
|
||||
public interface MPJBaseService<T> extends IService<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
Integer selectJoinCount(MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
<DTO, P extends IPage<?>> IPage<DTO> selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(MPJBaseJoin wrapper);
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
<P extends IPage<Map<String, Object>>> IPage<Map<String, Object>> selectJoinMapsPage(P page, MPJBaseJoin wrapper);
|
||||
public interface MPJBaseService<T> extends MPJJoinService<T>, MPJDeepService<T> {
|
||||
}
|
||||
|
@ -1,76 +1,16 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see ServiceImpl
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJBaseServiceImpl<M extends MPJBaseMapper<T>, T> extends ServiceImpl<M, T> implements MPJBaseService<T> {
|
||||
|
||||
/**
|
||||
* mybatis plus 3.4.3 bug
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/issues/I3SE8R
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/commit/7210b461b23211e6b95ca6de2d846aa392bdc28c
|
||||
*/
|
||||
@Override
|
||||
protected Class<T> currentMapperClass() {
|
||||
return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServiceImpl.class, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis plus 3.4.3 bug
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/issues/I3SE8R
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/commit/7210b461b23211e6b95ca6de2d846aa392bdc28c
|
||||
*/
|
||||
@Override
|
||||
protected Class<T> currentModelClass() {
|
||||
return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServiceImpl.class, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer selectJoinCount(MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <DTO, P extends IPage<?>> IPage<DTO> selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectJoinMap(MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectJoinMaps(MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P extends IPage<Map<String, Object>>> IPage<Map<String, Object>> selectJoinMapsPage(P page, MPJBaseJoin wrapper) {
|
||||
return baseMapper.selectJoinMapsPage(page, wrapper);
|
||||
public Class<T> currentModelClass() {
|
||||
return super.currentModelClass();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.github.yulichang.config;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.github.yulichang.exception.MPJException;
|
||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.InterceptorChain;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
@ -23,7 +25,9 @@ import java.util.List;
|
||||
@SuppressWarnings("SpringJavaAutowiredMembersInspection")
|
||||
public class InterceptorConfig implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@Autowired
|
||||
private static final Log logger = LogFactory.getLog(InterceptorConfig.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<SqlSessionFactory> sqlSessionFactoryList;
|
||||
@Autowired
|
||||
private MPJInterceptor mpjInterceptor;
|
||||
@ -48,6 +52,8 @@ public class InterceptorConfig implements ApplicationListener<ApplicationReadyEv
|
||||
} catch (Exception ignored) {
|
||||
throw new MPJException("mpjInterceptor exception");
|
||||
}
|
||||
} else {
|
||||
logger.warn("MPJ not define SqlSessionFactory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,21 @@ package com.github.yulichang.injector;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.injector.methods.*;
|
||||
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableMapperHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||
import com.github.yulichang.method.*;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* SQL 注入器
|
||||
@ -25,11 +26,47 @@ import java.util.Set;
|
||||
*/
|
||||
@ConditionalOnMissingBean(DefaultSqlInjector.class)
|
||||
public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
private static final Log logger = LogFactory.getLog(MPJSqlInjector.class);
|
||||
|
||||
@Override
|
||||
/**
|
||||
* 升级到 mybatis plus 3.4.3.2 后对之前的版本兼容
|
||||
*/
|
||||
@SuppressWarnings({"unused", "deprecation"})
|
||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
|
||||
List<AbstractMethod> list = super.getMethodList(mapperClass);
|
||||
List<AbstractMethod> list = Stream.of(
|
||||
new Insert(),
|
||||
new Delete(),
|
||||
new DeleteByMap(),
|
||||
new DeleteById(),
|
||||
new DeleteBatchByIds(),
|
||||
new Update(),
|
||||
new UpdateById(),
|
||||
new SelectById(),
|
||||
new SelectBatchByIds(),
|
||||
new SelectByMap(),
|
||||
new SelectOne(),
|
||||
new SelectCount(),
|
||||
new SelectMaps(),
|
||||
new SelectMapsPage(),
|
||||
new SelectObjs(),
|
||||
new SelectList(),
|
||||
new SelectPage()
|
||||
).collect(toList());
|
||||
list.addAll(getJoinMethod());
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis plus 3.4.3.2
|
||||
*/
|
||||
@Override
|
||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
|
||||
List<AbstractMethod> list = super.getMethodList(mapperClass, tableInfo);
|
||||
list.addAll(getJoinMethod());
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<AbstractMethod> getJoinMethod() {
|
||||
List<AbstractMethod> list = new ArrayList<>();
|
||||
list.add(new SelectJoinCount());
|
||||
list.add(new SelectJoinOne());
|
||||
list.add(new SelectJoinList());
|
||||
@ -40,30 +77,15 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis plus 3.4.3 bug
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/issues/I3SE8R
|
||||
* <p>
|
||||
* https://gitee.com/baomidou/mybatis-plus/commit/7210b461b23211e6b95ca6de2d846aa392bdc28c
|
||||
*/
|
||||
@Override
|
||||
public void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) {
|
||||
Class<?> modelClass = ReflectionKit.getSuperClassGenericType(mapperClass, Mapper.class, 0);
|
||||
if (modelClass != null) {
|
||||
String className = mapperClass.toString();
|
||||
Set<String> mapperRegistryCache = GlobalConfigUtils.getMapperRegistryCache(builderAssistant.getConfiguration());
|
||||
if (!mapperRegistryCache.contains(className)) {
|
||||
List<AbstractMethod> methodList = this.getMethodList(mapperClass);
|
||||
if (CollectionUtils.isNotEmpty(methodList)) {
|
||||
TableInfo tableInfo = TableInfoHelper.initTableInfo(builderAssistant, modelClass);
|
||||
// 循环注入自定义方法
|
||||
methodList.forEach(m -> m.inject(builderAssistant, mapperClass, modelClass, tableInfo));
|
||||
} else {
|
||||
logger.debug(mapperClass + ", No effective injection method was found.");
|
||||
}
|
||||
mapperRegistryCache.add(className);
|
||||
}
|
||||
}
|
||||
Class<?> modelClass = getSuperClassGenericType(mapperClass, Mapper.class, 0);
|
||||
super.inspectInject(builderAssistant, mapperClass);
|
||||
MPJTableMapperHelper.init(modelClass, mapperClass);
|
||||
}
|
||||
|
||||
public static Class<?> getSuperClassGenericType(final Class<?> clazz, final Class<?> genericIfc, final int index) {
|
||||
Class<?>[] typeArguments = GenericTypeResolver.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc);
|
||||
return null == typeArguments ? null : typeArguments[index];
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.yulichang.interceptor;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
@ -116,13 +117,13 @@ public class MPJInterceptor implements Interceptor {
|
||||
if (tableInfo != null && tableInfo.isAutoInitResultMap() && tableInfo.getEntityType() == resultType) {
|
||||
return ms.getConfiguration().getResultMap(tableInfo.getResultMap());
|
||||
}
|
||||
TableInfo infoDTO = MPJTableInfoHelper.getTableInfo(resultType);
|
||||
MPJTableInfo infoDTO = MPJTableInfoHelper.getTableInfo(resultType);
|
||||
if (infoDTO == null) {
|
||||
infoDTO = MPJTableInfoHelper.initTableInfo(ms.getConfiguration(),
|
||||
ms.getId().substring(0, ms.getId().lastIndexOf(".")), resultType);
|
||||
ms.getId().substring(0, ms.getId().lastIndexOf(".")), resultType, null);
|
||||
}
|
||||
if (infoDTO.isAutoInitResultMap()) {
|
||||
return ms.getConfiguration().getResultMap(infoDTO.getResultMap());
|
||||
if (infoDTO.getTableInfo().isAutoInitResultMap()) {
|
||||
return ms.getConfiguration().getResultMap(infoDTO.getTableInfo().getResultMap());
|
||||
}
|
||||
return new ResultMap.Builder(ms.getConfiguration(), ms.getId(), resultType, EMPTY_RESULT_MAPPING).build();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
/**
|
||||
* 主表别名
|
||||
*/
|
||||
private final SharedString alias = new SharedString(Constant.TABLE_ALIAS);
|
||||
private String alias = Constant.TABLE_ALIAS;
|
||||
|
||||
/**
|
||||
* 查询的列
|
||||
@ -90,6 +90,14 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
this.ignoreColumns = ignoreColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表别名(默认为 t 可以调用此方法修改,调用后才生效,所以最好第一个调用)
|
||||
*/
|
||||
public final MPJLambdaQueryWrapper<T> alias(String tableAlias) {
|
||||
this.alias = tableAlias;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* SELECT 部分 SQL 设置
|
||||
*
|
||||
@ -130,7 +138,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
public final MPJLambdaQueryWrapper<T> selectIgnore(SFunction<T, ?>... columns) {
|
||||
if (ArrayUtils.isNotEmpty(columns)) {
|
||||
for (SFunction<T, ?> s : columns) {
|
||||
ignoreColumns.add(Constant.TABLE_ALIAS + StringPool.DOT + getColumnCache(s).getColumn());
|
||||
ignoreColumns.add(this.alias + StringPool.DOT + super.columnToString(s, false));
|
||||
}
|
||||
}
|
||||
return typedThis;
|
||||
@ -138,7 +146,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
|
||||
@Override
|
||||
protected String columnToString(SFunction<T, ?> column, boolean onlyColumn) {
|
||||
return Constant.TABLE_ALIAS + StringPool.DOT + super.columnToString(column, onlyColumn);
|
||||
return this.alias + StringPool.DOT + super.columnToString(column, onlyColumn);
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> select(String... columns) {
|
||||
@ -166,7 +174,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
|
||||
Assert.notNull(info, "can not find table info");
|
||||
selectColumns.addAll(info.getFieldList().stream().filter(predicate).map(c ->
|
||||
Constant.TABLE_ALIAS + StringPool.DOT + c.getColumn()).collect(Collectors.toList()));
|
||||
this.alias + StringPool.DOT + c.getColumn()).collect(Collectors.toList()));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -177,7 +185,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
* @param clazz 主表class
|
||||
*/
|
||||
public final MPJLambdaQueryWrapper<T> selectAll(Class<T> clazz) {
|
||||
return selectAll(clazz, Constant.TABLE_ALIAS);
|
||||
return selectAll(clazz, this.alias);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,13 +194,14 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
* @param clazz 表实体
|
||||
* @param as 表别名
|
||||
*/
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public final MPJLambdaQueryWrapper<T> selectAll(Class<?> clazz, String as) {
|
||||
TableInfo info = TableInfoHelper.getTableInfo(clazz);
|
||||
Assert.notNull(info, "can not find table info");
|
||||
if (info.havePK()) {
|
||||
selectColumns.add(as + StringPool.DOT + info.getKeyColumn());
|
||||
}
|
||||
selectColumns.addAll(info.getFieldList().stream().map(i ->
|
||||
selectColumns.addAll(info.getFieldList().stream().filter(TableFieldInfo::isSelect).map(i ->
|
||||
as + StringPool.DOT + i.getColumn()).collect(Collectors.toList()));
|
||||
return typedThis;
|
||||
}
|
||||
@ -220,9 +229,12 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
return from.getStringValue();
|
||||
}
|
||||
|
||||
public boolean getAutoAlias() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias.getStringValue();
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
/**
|
||||
* 主表别名
|
||||
*/
|
||||
private final SharedString alias = new SharedString(Constant.TABLE_ALIAS);
|
||||
private String alias = Constant.TABLE_ALIAS;
|
||||
|
||||
/**
|
||||
* 查询的列
|
||||
@ -88,6 +88,14 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
this.ignoreColumns = ignoreColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表别名(默认为 t 可以调用此方法修改,调用后才生效,所以最好第一个调用)
|
||||
*/
|
||||
public final MPJQueryWrapper<T> alias(String tableAlias) {
|
||||
this.alias = tableAlias;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPJQueryWrapper<T> select(String... columns) {
|
||||
if (ArrayUtils.isNotEmpty(columns)) {
|
||||
@ -122,7 +130,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
|
||||
Assert.notNull(info, "can not find table info");
|
||||
selectColumns.addAll(info.getFieldList().stream().filter(predicate).map(c ->
|
||||
Constant.TABLE_ALIAS + StringPool.DOT + c.getColumn()).collect(Collectors.toList()));
|
||||
this.alias + StringPool.DOT + c.getColumn()).collect(Collectors.toList()));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -133,7 +141,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
* @param clazz 主表class
|
||||
*/
|
||||
public final MPJQueryWrapper<T> selectAll(Class<T> clazz) {
|
||||
selectAll(clazz, Constant.TABLE_ALIAS);
|
||||
selectAll(clazz, this.alias);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -149,7 +157,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
if (info.havePK()) {
|
||||
selectColumns.add(as + StringPool.DOT + info.getKeyColumn());
|
||||
}
|
||||
selectColumns.addAll(info.getFieldList().stream().map(i ->
|
||||
selectColumns.addAll(info.getFieldList().stream().filter(TableFieldInfo::isSelect).map(i ->
|
||||
as + StringPool.DOT + i.getColumn()).collect(Collectors.toList()));
|
||||
return typedThis;
|
||||
}
|
||||
@ -170,13 +178,18 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
return from.getStringValue();
|
||||
}
|
||||
|
||||
public boolean getAutoAlias() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias.getStringValue();
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个支持 lambda 函数写法的 wrapper
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public MPJLambdaQueryWrapper<T> lambda() {
|
||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), from, sqlSelect, paramNameSeq, paramNameValuePairs,
|
||||
expression, lastSql, sqlComment, sqlFirst, selectColumns, ignoreColumns);
|
||||
|
@ -6,6 +6,7 @@ import com.github.yulichang.toolkit.Constant;
|
||||
/**
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface MPJJoin<Children> extends MPJBaseJoin {
|
||||
|
||||
default Children leftJoin(String joinSql) {
|
||||
|
@ -84,6 +84,7 @@ public final class LambdaUtils {
|
||||
*
|
||||
* @param tableInfo 表信息
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void installCache(TableInfo tableInfo) {
|
||||
COLUMN_CACHE_MAP.put(tableInfo.getEntityType().getName(), createColumnCacheMap(tableInfo));
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import static java.util.stream.Collectors.toMap;
|
||||
* @author hcl
|
||||
* @since 2016-09-22
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class ReflectionKit {
|
||||
private static final Log logger = LogFactory.getLog(ReflectionKit.class);
|
||||
/**
|
||||
@ -181,16 +182,4 @@ public final class ReflectionKit {
|
||||
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
|
||||
return (clazz.isPrimitive() && clazz != void.class ? PRIMITIVE_TYPE_TO_WRAPPER_MAP.get(clazz) : clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置可访问对象的可访问权限为 true
|
||||
*
|
||||
* @param object 可访问的对象
|
||||
* @param <T> 类型
|
||||
* @return 返回设置后的对象
|
||||
*/
|
||||
public static <T extends AccessibleObject> T setAccessible(T object) {
|
||||
return AccessController.doPrivileged(new SetAccessibleAction<>(object));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Wrappers {
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* copy mp before 3.4.3 {@link com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda}
|
||||
* copy mp before 3.4.3
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class SerializedLambda implements Serializable {
|
||||
|
@ -11,6 +11,7 @@ import java.util.function.BiPredicate;
|
||||
* <p>
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Compare<Children> extends Serializable {
|
||||
|
||||
/**
|
||||
@ -65,6 +66,7 @@ public interface Compare<Children> extends Serializable {
|
||||
/**
|
||||
* ignore
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
default <R> Children eq(SFunction<R, ?> column, Object val) {
|
||||
return eq(true, column, val);
|
||||
}
|
||||
|
@ -11,12 +11,13 @@ import java.util.function.Consumer;
|
||||
* <p>
|
||||
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public interface Func<Children> extends Serializable {
|
||||
|
||||
/**
|
||||
* ignore
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
default <R> Children isNull(SFunction<R, ?> column) {
|
||||
return isNull(true, column);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.io.Serializable;
|
||||
* 无改动 在mybatis 3.4.2 升级 3.4.3 后有改动 exists 和 not exists
|
||||
* 为了保证 mybatis plus 3.4.3之前的也能正常使用
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Join<Children> extends Serializable {
|
||||
|
||||
/**
|
||||
|
@ -8,55 +8,120 @@ import com.github.yulichang.wrapper.interfaces.on.OnFunction;
|
||||
/**
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface LambdaJoin<Children> extends MPJBaseJoin {
|
||||
|
||||
/**
|
||||
* left join
|
||||
*
|
||||
* @param clazz 关联的实体类
|
||||
* @param left 条件
|
||||
* @param right 条件
|
||||
*/
|
||||
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return leftJoin(true, clazz, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* left join
|
||||
* <p>
|
||||
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||
*
|
||||
* @param clazz 关联的实体类
|
||||
* @param function 条件
|
||||
*/
|
||||
default <T> Children leftJoin(Class<T> clazz, OnFunction function) {
|
||||
return leftJoin(true, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* left join
|
||||
*
|
||||
* @param condition 是否执行
|
||||
* @param clazz 关联的实体类
|
||||
* @param left 条件
|
||||
* @param right 条件
|
||||
*/
|
||||
default <T, X> Children leftJoin(boolean condition, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return leftJoin(condition, clazz, on -> on.eq(left, right));
|
||||
}
|
||||
|
||||
/**
|
||||
* left join
|
||||
* <p>
|
||||
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
|
||||
*
|
||||
* @param condition 是否执行
|
||||
* @param clazz 关联实体类
|
||||
* @param function 条件
|
||||
*/
|
||||
default <T> Children leftJoin(boolean condition, Class<T> clazz, OnFunction function) {
|
||||
return join(Constant.LEFT_JOIN, condition, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T, X> Children rightJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return rightJoin(true, clazz, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T> Children rightJoin(Class<T> clazz, OnFunction function) {
|
||||
return rightJoin(true, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T, X> Children rightJoin(boolean condition, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return rightJoin(condition, clazz, on -> on.eq(left, right));
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T> Children rightJoin(boolean condition, Class<T> clazz, OnFunction function) {
|
||||
return join(Constant.RIGHT_JOIN, condition, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T, X> Children innerJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return innerJoin(true, clazz, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T> Children innerJoin(Class<T> clazz, OnFunction function) {
|
||||
return innerJoin(true, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T, X> Children innerJoin(boolean condition, Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||
return innerJoin(condition, clazz, on -> on.eq(left, right));
|
||||
}
|
||||
|
||||
/**
|
||||
* ignore 参考 left join
|
||||
*/
|
||||
default <T> Children innerJoin(boolean condition, Class<T> clazz, OnFunction function) {
|
||||
return join(Constant.INNER_JOIN, condition, clazz, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询基类 可以直接调用此方法实现以上所有功能
|
||||
*
|
||||
* @param keyWord 连表关键字
|
||||
* @param condition 是否执行
|
||||
* @param clazz 连表实体类
|
||||
* @param function 关联条件
|
||||
*/
|
||||
<T> Children join(String keyWord, boolean condition, Class<T> clazz, OnFunction function);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import java.io.Serializable;
|
||||
*
|
||||
* @since 1.1.8
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface OnCompare<Children> extends Serializable {
|
||||
/**
|
||||
* ignore
|
||||
|
@ -1,4 +1,6 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.github.yulichang.interceptor.MPJInterceptor,\
|
||||
com.github.yulichang.injector.MPJSqlInjector,\
|
||||
com.github.yulichang.config.InterceptorConfig
|
||||
com.github.yulichang.config.InterceptorConfig,\
|
||||
com.github.yulichang.config.MappingConfig,\
|
||||
com.github.yulichang.toolkit.SpringContentUtils
|
||||
|
Loading…
x
Reference in New Issue
Block a user