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
d2084ba1ae
commit
14d7e954b0
@ -46,7 +46,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-core</artifactId>
|
||||
<artifactId>mybatis-plus-join-extension</artifactId>
|
||||
<version>1.4.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,9 +6,10 @@ import com.github.yulichang.autoconfigure.conditional.MPJSqlInjectorCondition;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.extension.mapping.config.MappingConfig;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import com.github.yulichang.injector.MPJSqlInjector;
|
||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.slf4j.Logger;
|
||||
@ -127,7 +128,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
@Override
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
new com.github.yulichang.config.MappingConfig();
|
||||
new MappingConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,99 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.mapper.MPJJoinMapper;
|
||||
import com.github.yulichang.base.mapper.MPJRelationMapper;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see BaseMapper
|
||||
*/
|
||||
public interface MPJBaseMapper<T> extends MPJJoinMapper<T>, MPJRelationMapper<T> {
|
||||
public interface MPJBaseMapper<T> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
int deleteJoin(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoin(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoinAndNull(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Long selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
* @param <DTO> 分页返回对象
|
||||
*/
|
||||
<DTO, P extends IPage<DTO>> P selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
<P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
}
|
||||
|
@ -1,13 +1,98 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.github.yulichang.base.service.MPJJoinService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础service
|
||||
* 目前包含两个模块 连表查询 和 关系映射
|
||||
*
|
||||
* @author yulichang
|
||||
* @see MPJJoinService
|
||||
*/
|
||||
public interface MPJBaseService<T> extends MPJJoinService<T> {
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public interface MPJBaseService<T> extends IService<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default boolean deleteJoin(MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).deleteJoin(wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoin(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoin(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoinAndNull(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoinAndNull(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Long selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<DTO>> P selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -1,99 +0,0 @@
|
||||
package com.github.yulichang.base.mapper;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see BaseMapper
|
||||
*/
|
||||
public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
int deleteJoin(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoin(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoinAndNull(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Long selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
* @param <DTO> 分页返回对象
|
||||
*/
|
||||
<DTO, P extends IPage<DTO>> P selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
<P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package com.github.yulichang.base.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.relation.Relation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 注解映射Mapper 用于替代 MPJDeepMapper
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.3
|
||||
*/
|
||||
public interface MPJRelationMapper<T> {
|
||||
|
||||
/**
|
||||
* 通过注解实现单表多次查询
|
||||
*
|
||||
* @param function BaseMapper调用方法
|
||||
* @see com.github.yulichang.annotation.EntityMapping
|
||||
* @see com.github.yulichang.annotation.FieldMapping
|
||||
*/
|
||||
default <R, M extends BaseMapper<T>> R selectRelation(Function<M, R> function) {
|
||||
return selectRelation(function, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过注解实现单表多次查询
|
||||
*
|
||||
* @param function BaseMapper调用方法
|
||||
* @param list 属性过滤, 可以只查询需要映射的属性
|
||||
* @see com.github.yulichang.annotation.EntityMapping
|
||||
* @see com.github.yulichang.annotation.FieldMapping
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default <R, M extends BaseMapper<T>> R selectRelation(Function<M, R> function, List<SFunction<T, ?>> list) {
|
||||
R r = function.apply((M) this);
|
||||
if (Objects.isNull(r)) {
|
||||
return null;
|
||||
} else if (r instanceof List) {
|
||||
List<T> data = (List<T>) r;
|
||||
if (CollectionUtils.isEmpty(data)) {
|
||||
return r;
|
||||
} else {
|
||||
T t = data.get(0);
|
||||
if (Map.class.isAssignableFrom(t.getClass())) {
|
||||
throw ExceptionUtils.mpe("暂不支持Map类型映射");
|
||||
}
|
||||
if (Object.class == t.getClass()) {
|
||||
return r;
|
||||
}
|
||||
return (R) Relation.list(data, list);
|
||||
}
|
||||
} else if (r instanceof IPage) {
|
||||
IPage<T> data = (IPage<T>) r;
|
||||
if (!CollectionUtils.isEmpty(data.getRecords())) {
|
||||
T t = data.getRecords().get(0);
|
||||
if (Map.class.isAssignableFrom(t.getClass())) {
|
||||
throw ExceptionUtils.mpe("暂不支持Map类型映射");
|
||||
}
|
||||
if (Object.class == t.getClass()) {
|
||||
return r;
|
||||
}
|
||||
Relation.list(data.getRecords(), list);
|
||||
}
|
||||
return r;
|
||||
} else if (r instanceof Integer) {
|
||||
return r;
|
||||
} else if (r instanceof Long) {
|
||||
return r;
|
||||
} else if (r instanceof Boolean) {
|
||||
return r;
|
||||
} else if (Object.class == r.getClass()) {
|
||||
return r;
|
||||
} else {
|
||||
return (R) Relation.one((T) r, list);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.github.yulichang.base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see IService
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface MPJJoinService<T> extends IService<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Long selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<DTO>> P selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.github.yulichang.base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.annotation.EntityMapping;
|
||||
import com.github.yulichang.annotation.FieldMapping;
|
||||
import com.github.yulichang.base.mapper.MPJRelationMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 深度查询
|
||||
* <p>
|
||||
* 对配置了映射注解的字段进行查询
|
||||
* 目前查询深度只支持2级(只解析当前实体类的映射注解,不会对查询结果再次解析注解)
|
||||
* 多级查询可能存在循环引用的问题,也可能会导致全量查询
|
||||
* 用于替换deep
|
||||
*
|
||||
* @author yulichang
|
||||
* @see EntityMapping
|
||||
* @see FieldMapping
|
||||
* @since 1.4.4
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public interface MPJRelationService<T> extends IService<T> {
|
||||
|
||||
default <R, M extends BaseMapper<T>> R selectRelation(Function<M, R> function) {
|
||||
return selectRelation(function, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过注解实现单表多次查询
|
||||
*
|
||||
* @param function BaseMapper调用方法
|
||||
* @param list 属性过滤, 可以只查询需要映射的属性
|
||||
* @see com.github.yulichang.annotation.EntityMapping
|
||||
* @see com.github.yulichang.annotation.FieldMapping
|
||||
*/
|
||||
default <R, M extends BaseMapper<T>> R selectRelation(Function<M, R> function, List<SFunction<T, ?>> list) {
|
||||
return ((MPJRelationMapper<T>) getBaseMapper()).selectRelation(function, list);
|
||||
}
|
||||
|
||||
}
|
@ -12,8 +12,8 @@ import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.github.yulichang.adapter.v3431.AbstractMethodV3431;
|
||||
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
||||
import com.github.yulichang.method.*;
|
||||
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.VersionUtils;
|
||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||
|
@ -3,11 +3,11 @@ package com.github.yulichang.interceptor;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
||||
import com.github.yulichang.method.MPJResultType;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
@ -24,7 +23,7 @@ public class Delete extends com.baomidou.mybatisplus.core.injector.methods.Delet
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
@ -24,7 +23,7 @@ public class SelectCount extends com.baomidou.mybatisplus.core.injector.methods.
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -25,7 +24,7 @@ public class SelectList extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -25,7 +24,7 @@ public class SelectMaps extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -25,7 +24,7 @@ public class SelectMapsPage extends com.baomidou.mybatisplus.core.injector.metho
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -25,7 +24,7 @@ public class SelectObjs extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -30,7 +29,7 @@ public class SelectOne extends com.baomidou.mybatisplus.core.injector.methods.Se
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
@ -25,7 +24,7 @@ public class SelectPage extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,9 +2,13 @@ package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.method.MPJBaseMethod;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 兼容原生方法
|
||||
@ -22,4 +26,31 @@ public interface TableAlias extends Constants, MPJBaseMethod {
|
||||
mpjTableName(tableInfo) + " ${ew.alias} " + NEWLINE + from, tableInfo.getTableName());
|
||||
return SPACE + alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制tableInfo对象
|
||||
* 由于各个版本的MP的TableInfo对象存在差异,为了兼容性采用反射,而不是getter setter
|
||||
*/
|
||||
default TableInfo copyAndSetTableName(TableInfo tableInfo, String tableName) {
|
||||
try {
|
||||
TableInfo table;
|
||||
try {
|
||||
table = TableInfo.class.getDeclaredConstructor(Class.class).newInstance(tableInfo.getEntityType());
|
||||
} catch (Exception e) {
|
||||
table = TableInfo.class.getDeclaredConstructor(Configuration.class, Class.class).newInstance(tableInfo.getConfiguration(), tableInfo.getEntityType());
|
||||
}
|
||||
//反射拷贝对象
|
||||
Field[] fields = TableInfo.class.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
f.setAccessible(true);
|
||||
f.set(table, f.get(tableInfo));
|
||||
}
|
||||
Field field = TableInfo.class.getDeclaredField("tableName");
|
||||
field.setAccessible(true);
|
||||
field.set(table, tableName);
|
||||
return table;
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.mpe("TableInfo 对象拷贝失败 -> " + tableInfo.getEntityType().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.method.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
@ -24,7 +23,7 @@ public class Update extends com.baomidou.mybatisplus.core.injector.methods.Updat
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
return super.injectMappedStatement(mapperClass, modelClass,
|
||||
MPJTableInfoHelper.copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
copyAndSetTableName(tableInfo, getTableName(tableInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +83,7 @@ public class JoinWrappers {
|
||||
}
|
||||
|
||||
/**
|
||||
* JoinWrappers.delete(User.class)
|
||||
* JoinWrappers.delete("t", User.class)
|
||||
*/
|
||||
public static <T> DeleteJoinWrapper<T> delete(String alias, Class<T> clazz) {
|
||||
return new DeleteJoinWrapper<>(clazz, alias);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.github.yulichang.mapper;
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
@ -4,7 +4,6 @@ package com.github.yulichang.toolkit;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
||||
import java.util.Objects;
|
||||
|
64
mybatis-plus-join-extension/pom.xml
Normal file
64
mybatis-plus-join-extension/pom.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<version>1.4.4.1</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-extension</artifactId>
|
||||
<version>1.4.4.1</version>
|
||||
<name>mybatis-plus-join-extension</name>
|
||||
|
||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>mybatis-plus-join</id>
|
||||
<name>yulichang</name>
|
||||
<email>yu_lichang@qq.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</developerConnection>
|
||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-core</artifactId>
|
||||
<version>1.4.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>3.5.3.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,14 +1,15 @@
|
||||
package com.github.yulichang.base.mapper;
|
||||
package com.github.yulichang.extension.mapping.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.base.mapper.wrapper.MappingQuery;
|
||||
import com.github.yulichang.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.mapper.MPJTableInfo;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableInfo;
|
||||
import com.github.yulichang.extension.mapping.wrapper.MappingQuery;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -194,41 +195,6 @@ public interface MPJDeepMapper<T> extends BaseMapper<T> {
|
||||
return mpjQueryMapping(selectList(queryWrapper), property);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询全部记录
|
||||
*
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
*/
|
||||
default List<Map<String, Object>> selectMapsDeep(Class<T> clazz, Wrapper<T> queryWrapper) {
|
||||
return mpjQueryMapMapping(selectMaps(queryWrapper), clazz, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 entity 条件,查询全部记录(并翻页)
|
||||
* <p>
|
||||
* JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
|
||||
*
|
||||
* @param clazz 实体类class
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
* @param property 需要关联的字段
|
||||
*/
|
||||
default <R> List<Map<String, Object>> selectMapsDeep(Class<T> clazz, Wrapper<T> queryWrapper, SFunction<T, R>... property) {
|
||||
return mpjQueryMapMapping(selectMaps(queryWrapper), clazz, Arrays.asList(property));
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对可变参数堆污染提供的重载
|
||||
* list为null或空,会查询全部映射关系
|
||||
* <p>
|
||||
* 例: selectMapsDeep(UserDO.class, queryWrapper, Arrays.asList(User::getId, ... ))
|
||||
*
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
* @param property 需要关联的字段
|
||||
*/
|
||||
default <R> List<Map<String, Object>> selectMapsDeep(Class<T> clazz, Wrapper<T> queryWrapper, List<SFunction<T, R>> property) {
|
||||
return mpjQueryMapMapping(selectMaps(queryWrapper), clazz, property);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 entity 条件,查询全部记录(并翻页)
|
||||
*
|
||||
@ -272,54 +238,6 @@ public interface MPJDeepMapper<T> extends BaseMapper<T> {
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 entity 条件,查询全部记录(并翻页)
|
||||
*
|
||||
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
*/
|
||||
default <R, E extends IPage<Map<String, Object>>> E selectMapsPageDeep(E page, Class<T> clazz, Wrapper<T> queryWrapper) {
|
||||
E e = selectMapsPage(page, queryWrapper);
|
||||
mpjQueryMapMapping(e.getRecords(), clazz, null);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 entity 条件,查询全部记录(并翻页)
|
||||
* <p>
|
||||
* JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
|
||||
*
|
||||
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
* @param property 需要关联的字段
|
||||
*/
|
||||
default <R, E extends IPage<Map<String, Object>>> E selectMapsPageDeep(E page, Class<T> clazz, Wrapper<T> queryWrapper,
|
||||
SFunction<T, R>... property) {
|
||||
E e = selectMapsPage(page, queryWrapper);
|
||||
mpjQueryMapMapping(e.getRecords(), clazz, Arrays.asList(property));
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对可变参数堆污染提供的重载
|
||||
* list为null或空,会查询全部映射关系
|
||||
* <p>
|
||||
* 例: selectMapsPage(page, UserDO.class, queryWrapper, Arrays.asList(User::getId, ... ))
|
||||
*
|
||||
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
|
||||
* @param queryWrapper 实体对象封装操作类(可以为 null)
|
||||
* @param property 需要关联的字段
|
||||
*/
|
||||
default <R, E extends IPage<Map<String, Object>>> E selectMapsPageDeep(E page, Class<T> clazz, Wrapper<T> queryWrapper,
|
||||
List<SFunction<T, R>> property) {
|
||||
E e = selectMapsPage(page, queryWrapper);
|
||||
mpjQueryMapMapping(e.getRecords(), clazz, property);
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询映射关系<br/>
|
||||
* 对结果进行二次查询<br/>
|
@ -1,4 +1,4 @@
|
||||
package com.github.yulichang.base.service;
|
||||
package com.github.yulichang.extension.mapping.base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.annotation.EntityMapping;
|
||||
import com.github.yulichang.annotation.FieldMapping;
|
||||
import com.github.yulichang.base.mapper.MPJDeepMapper;
|
||||
import com.github.yulichang.extension.mapping.base.MPJDeepMapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
@ -1,8 +1,8 @@
|
||||
package com.github.yulichang.config;
|
||||
package com.github.yulichang.extension.mapping.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
||||
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
|
||||
/**
|
||||
* 关系映射配置
|
@ -1,4 +1,4 @@
|
||||
package com.github.yulichang.mapper;
|
||||
package com.github.yulichang.extension.mapping.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
@ -1,7 +1,6 @@
|
||||
package com.github.yulichang.mapper;
|
||||
package com.github.yulichang.extension.mapping.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
@ -1,4 +1,4 @@
|
||||
package com.github.yulichang.mapper;
|
||||
package com.github.yulichang.extension.mapping.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import lombok.Data;
|
@ -1,15 +1,13 @@
|
||||
package com.baomidou.mybatisplus.core.metadata;
|
||||
package com.github.yulichang.extension.mapping.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.annotation.EntityMapping;
|
||||
import com.github.yulichang.annotation.FieldMapping;
|
||||
import com.github.yulichang.exception.MPJException;
|
||||
import com.github.yulichang.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.mapper.MPJTableInfo;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -21,12 +19,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* 拷贝 {@link TableInfoHelper}
|
||||
*
|
||||
* <p>用于构建resultType(DTO)对应的TableInfo
|
||||
* <p>拷贝这个类用于更好的兼容mybatis-plus的全部功能
|
||||
* <p>由于 {@link TableInfo} 权限限制,所以新建 com.baomidou.mybatisplus.core.metadata 这个包
|
||||
* <p>为什么不把 {@link TableInfo} 这个类拷贝出来? 因为无法限制用户使用那个版本, 而TableInfo会随着版本而改动,
|
||||
* 使用 mybatis-plus 的TableInfo能够兼容所有版本,也能跟好的维护
|
||||
*
|
||||
* @author yulichang
|
||||
* @see TableInfoHelper
|
||||
*/
|
||||
@ -130,28 +122,5 @@ public class MPJTableInfoHelper {
|
||||
mpjTableInfo.setFieldList(mpjFieldList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制tableInfo对象
|
||||
* 由于各个版本的MP的TableInfo对象存在差异,为了兼容性采用反射,而不是getter setter
|
||||
*/
|
||||
public static TableInfo copyAndSetTableName(TableInfo tableInfo, String tableName) {
|
||||
try {
|
||||
TableInfo table;
|
||||
try {
|
||||
table = TableInfo.class.getDeclaredConstructor(Class.class).newInstance(tableInfo.getEntityType());
|
||||
} catch (Exception e) {
|
||||
table = TableInfo.class.getDeclaredConstructor(Configuration.class, Class.class).newInstance(tableInfo.getConfiguration(), tableInfo.getEntityType());
|
||||
}
|
||||
//反射拷贝对象
|
||||
Field[] fields = TableInfo.class.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
f.setAccessible(true);
|
||||
f.set(table, f.get(tableInfo));
|
||||
}
|
||||
table.setTableName(tableName);
|
||||
return table;
|
||||
} catch (Exception e) {
|
||||
throw new MPJException("TableInfo 对象拷贝失败 -> " + tableInfo.getEntityType().getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package com.github.yulichang.relation;
|
||||
package com.github.yulichang.extension.mapping.relation;
|
||||
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.base.mapper.wrapper.MappingQuery;
|
||||
import com.github.yulichang.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.mapper.MPJTableInfo;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableInfo;
|
||||
import com.github.yulichang.extension.mapping.wrapper.MappingQuery;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
|
||||
import java.util.ArrayList;
|
@ -1,10 +1,10 @@
|
||||
package com.github.yulichang.base.mapper.wrapper;
|
||||
package com.github.yulichang.extension.mapping.wrapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.mapper.MPJMappingWrapper;
|
||||
import com.github.yulichang.mapper.MPJTableFieldInfo;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJMappingWrapper;
|
||||
import com.github.yulichang.extension.mapping.mapper.MPJTableFieldInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.test.join.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.base.mapper.MPJDeepMapper;
|
||||
import com.github.yulichang.extension.mapping.base.MPJDeepMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
Loading…
x
Reference in New Issue
Block a user