diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml
index 3828033..7c22f84 100644
--- a/mybatis-plus-join-annotation/pom.xml
+++ b/mybatis-plus-join-annotation/pom.xml
@@ -42,13 +42,4 @@
github
UTF-8
-
-
-
- com.baomidou
- mybatis-plus-core
- 3.5.3.1
- provided
-
-
diff --git a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java
index 847cee2..5be9478 100644
--- a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java
+++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java
@@ -10,7 +10,7 @@ import java.lang.annotation.*;
* @since 1.2.0
*/
@Documented
-@SuppressWarnings("unused")
+@SuppressWarnings({"unused"})
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
public @interface EntityMapping {
@@ -40,25 +40,6 @@ public @interface EntityMapping {
*/
boolean isThrowExp() default true;
- /**
- * 针对查询结果map的时候使用
- * 默认为thisField对应的数据库列名
- *
- * 如果此类是以map方式查询的
- * 并且查询出来的map的key不是thisField对应的数据库列名就需要设置
- */
- String thisMapKey() default "";
-
- /**
- * isMap为true时生效
- * 针对查询结果map的时候使用
- * 默认为joinField对应的数据库列名
- *
- * 如果此类是以map方式查询的
- * 并且查询出来的map的key不是thisField对应的数据库列名就需要设置
- */
- String joinMapKey() default "";
-
/**
* 映射表查询条件之 select
* 等效于 Wrappers.query().select(xxx);
diff --git a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java
index 5f310a0..ae16709 100644
--- a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java
+++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java
@@ -10,7 +10,7 @@ import java.lang.annotation.*;
* @since 1.2.0
*/
@Documented
-@SuppressWarnings("unused")
+@SuppressWarnings({"unused"})
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
public @interface FieldMapping {
@@ -45,25 +45,6 @@ public @interface FieldMapping {
*/
String select();
- /**
- * 针对查询结果map的时候使用
- * 默认为thisField对应的数据库列名
- *
- * 如果此类是以map方式查询的
- * 并且查询出来的map的key不是thisField对应的数据库列名就需要设置
- */
- String thisMapKey() default "";
-
- /**
- * isMap为true时生效
- * 针对查询结果map的时候使用
- * 默认为joinField对应的数据库列名
- *
- * 如果此类是以map方式查询的
- * 并且查询出来的map的key不是thisField对应的数据库列名就需要设置
- */
- String joinMapKey() default "";
-
/**
* 映射表查询条件之 first
* 等效于 Wrappers.query().first(xxx);
diff --git a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java
index 8c09726..01b60c8 100644
--- a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java
+++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java
@@ -1,6 +1,7 @@
package com.github.yulichang.annotation;
-import com.baomidou.mybatisplus.core.enums.SqlKeyword;
+
+import com.github.yulichang.annotation.enums.SqlKeyword;
/**
* 映射表条件
diff --git a/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/enums/SqlKeyword.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/enums/SqlKeyword.java
new file mode 100644
index 0000000..5b44b84
--- /dev/null
+++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/enums/SqlKeyword.java
@@ -0,0 +1,27 @@
+package com.github.yulichang.annotation.enums;
+
+/**
+ * @author yulichang
+ * @since 1.4.5
+ */
+public enum SqlKeyword {
+ NOT,
+ IN,
+ NOT_IN,
+ LIKE,
+ NOT_LIKE,
+ EQ,
+ NE,
+ GT,
+ GE,
+ LT,
+ LE,
+ IS_NULL,
+ IS_NOT_NULL,
+ BETWEEN,
+ NOT_BETWEEN,
+ ;
+
+ SqlKeyword() {
+ }
+}
diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java
index 6295123..2d37bf3 100644
--- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java
+++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java
@@ -65,6 +65,7 @@ public class MybatisPlusJoinAutoConfiguration {
ConfigProperties.joinPrefix = properties.getJoinPrefix();
ConfigProperties.logicDelType = "where".equalsIgnoreCase(properties.getLogicDelType()) ?
LogicDelTypeEnum.WHERE : LogicDelTypeEnum.ON;
+ ConfigProperties.mappingMaxCount = properties.getMappingMaxCount();
}
/**
diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
index 2f758fb..e42d265 100644
--- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
+++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
@@ -44,4 +44,9 @@ public class MybatisPlusJoinProperties {
* 逻辑删除类型 支持 where on
*/
private String logicDelType = "where";
+
+ /**
+ * 映射查询最大深度
+ */
+ private int mappingMaxCount = 5;
}
diff --git a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index 05f30f3..407dc88 100644
--- a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -43,6 +43,12 @@
"defaultValue": "where",
"type": "java.lang.String",
"description": "逻辑删除的位置支持where和on两个."
+ },
+ {
+ "name": "mybatis-plus-join.mapping-max-count",
+ "defaultValue": 5,
+ "type": "java.lang.Integer",
+ "description": "映射查询最大深度."
}
],
"hints": [
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java
index b7ebe5a..a58bd4f 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java
@@ -14,7 +14,7 @@ import java.util.Map;
*
* @author yulichang
*/
-@SuppressWarnings({"unused", "unchecked"})
+@SuppressWarnings({"unused"})
public interface MPJBaseService extends IService {
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
index 403644f..80735b4 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
@@ -30,6 +30,10 @@ public class ConfigProperties {
* 逻辑删除类型 支持 where on
*/
public static LogicDelTypeEnum logicDelType = LogicDelTypeEnum.WHERE;
+ /**
+ * 逻辑删除类型 支持 where on
+ */
+ public static int mappingMaxCount = 5;
/**
* TableInfo适配器
*/
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java
index f1a48d9..e24f436 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java
@@ -31,6 +31,7 @@ public interface TableAlias extends Constants, MPJBaseMethod {
* 复制tableInfo对象
* 由于各个版本的MP的TableInfo对象存在差异,为了兼容性采用反射,而不是getter setter
*/
+ @SuppressWarnings("JavaReflectionMemberAccess")
default TableInfo copyAndSetTableName(TableInfo tableInfo, String tableName) {
try {
TableInfo table;
diff --git a/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/base/MPJDeepMapper.java b/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/base/MPJDeepMapper.java
deleted file mode 100644
index a6321f6..0000000
--- a/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/base/MPJDeepMapper.java
+++ /dev/null
@@ -1,413 +0,0 @@
-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.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.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;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * 关联查询
- *
- * @author yulichang
- * @see BaseMapper
- */
-@SuppressWarnings({"unused", "unchecked"})
-public interface MPJDeepMapper extends BaseMapper {
-
- /**
- * 根据 ID 查询 并关联全部映射
- *
- * @param id 主键ID
- */
- default T selectByIdDeep(Serializable id) {
- return mpjQueryMapping(selectById(id), null);
- }
-
- /**
- * 根据 ID 查询 并关联指定映射
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param id 主键ID
- * @param property 需要关联的字段
- */
- default T selectByIdDeep(Serializable id, SFunction... property) {
- return mpjQueryMapping(selectById(id), Arrays.asList(property));
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectByIdDeep(1, Arrays.asList(User::getId, ... ))
- *
- * @param id 主键ID
- * @param property 需要关联的字段
- */
- default T selectByIdDeep(Serializable id, List> property) {
- return mpjQueryMapping(selectById(id), property);
- }
-
- /**
- * 查询(根据ID 批量查询)
- *
- * @param idList 主键ID列表(不能为 null 以及 empty)
- */
- default List selectBatchIdsDeep(Collection extends Serializable> idList) {
- return mpjQueryMapping(selectBatchIds(idList), null);
- }
-
- /**
- * 查询(根据ID 批量查询)
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param idList 主键ID列表(不能为 null 以及 empty)
- * @param property 需要关联的字段
- */
- default List selectBatchIdsDeep(Collection extends Serializable> idList, SFunction... property) {
- return mpjQueryMapping(selectBatchIds(idList), Arrays.asList(property));
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectBatchIdsDeep(idList, Arrays.asList(User::getId, ... ))
- *
- * @param idList 主键ID列表(不能为 null 以及 empty)
- * @param property 需要关联的字段
- */
- default List selectBatchIdsDeep(Collection extends Serializable> idList, List> property) {
- return mpjQueryMapping(selectBatchIds(idList), property);
- }
-
- /**
- * 查询(根据 columnMap 条件)
- *
- * @param columnMap 表字段 map 对象
- */
- default List selectByMapDeep(Map columnMap) {
- return mpjQueryMapping(selectByMap(columnMap), null);
- }
-
- /**
- * 查询(根据 columnMap 条件)
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param columnMap 表字段 map 对象
- * @param property 需要关联的字段
- */
- default List selectByMapDeep(Map columnMap, SFunction... property) {
- return mpjQueryMapping(selectByMap(columnMap), Arrays.asList(property));
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectByMapDeep(columnMap, Arrays.asList(User::getId, ... ))
- *
- * @param columnMap 表字段 map 对象
- * @param property 需要关联的字段
- */
- default List selectByMapDeep(Map columnMap, List> property) {
- return mpjQueryMapping(selectByMap(columnMap), property);
- }
-
- /**
- * 根据 entity 条件,查询一条记录
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- */
- default T selectOneDeep(Wrapper queryWrapper) {
- return mpjQueryMapping(selectOne(queryWrapper), null);
- }
-
- /**
- * 根据 entity 条件,查询一条记录
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default T selectOneDeep(Wrapper queryWrapper, SFunction... property) {
- return mpjQueryMapping(selectOne(queryWrapper), Arrays.asList(property));
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectOneDeep(queryWrapper, Arrays.asList(User::getId, ... ))
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default T selectOneDeep(Wrapper queryWrapper, List> property) {
- return mpjQueryMapping(selectOne(queryWrapper), property);
- }
-
- /**
- * 根据 entity 条件,查询全部记录
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- */
- default List selectListDeep(Wrapper queryWrapper) {
- return mpjQueryMapping(selectList(queryWrapper), null);
- }
-
- /**
- * 根据 entity 条件,查询全部记录
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default List selectListDeep(Wrapper queryWrapper, SFunction... property) {
- return mpjQueryMapping(selectList(queryWrapper), Arrays.asList(property));
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectListDeep(queryWrapper, Arrays.asList(User::getId, ... ))
- *
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default List selectListDeep(Wrapper queryWrapper, List> property) {
- return mpjQueryMapping(selectList(queryWrapper), property);
- }
-
- /**
- * 根据 entity 条件,查询全部记录(并翻页)
- *
- * @param page 分页查询条件(可以为 RowBounds.DEFAULT)
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- */
- default > E selectPageDeep(E page, Wrapper queryWrapper) {
- E e = selectPage(page, queryWrapper);
- mpjQueryMapping(e.getRecords(), null);
- return e;
- }
-
- /**
- * 根据 entity 条件,查询全部记录(并翻页)
- *
- * JDK 默认不推荐泛型数组,会引起 Java堆污染(Heap Pollution)
- *
- * @param page 分页查询条件(可以为 RowBounds.DEFAULT)
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default > E selectPageDeep(E page, Wrapper queryWrapper, SFunction... property) {
- E e = selectPage(page, queryWrapper);
- mpjQueryMapping(e.getRecords(), Arrays.asList(property));
- return e;
- }
-
- /**
- * 针对可变参数堆污染提供的重载
- * list为null或空,会查询全部映射关系
- *
- * 例: selectPageDeep(page, queryWrapper, Arrays.asList(User::getId, ... ))
- *
- * @param page 分页查询条件(可以为 RowBounds.DEFAULT)
- * @param queryWrapper 实体对象封装操作类(可以为 null)
- * @param property 需要关联的字段
- */
- default > E selectPageDeep(E page, Wrapper queryWrapper, List> property) {
- E e = selectPage(page, queryWrapper);
- mpjQueryMapping(e.getRecords(), property);
- return e;
- }
-
- /**
- * 查询映射关系
- * 对结果进行二次查询
- * 可以自行查询然后在通过此方法进行二次查询
- * list为null或空,会查询全部映射关系
- *
- * @param t 第一次查询结果
- */
- default T mpjQueryMapping(T t, List> property) {
- if (t == null) {
- return null;
- }
- MPJTableInfo tableInfo = MPJTableInfoHelper.getTableInfo(t.getClass());
- if (tableInfo.isHasMappingOrField()) {
- boolean hasProperty = CollectionUtils.isNotEmpty(property);
- List list = hasProperty ? property.stream().map(LambdaUtils::getName).collect(
- Collectors.toList()) : null;
- for (MPJTableFieldInfo fieldInfo : tableInfo.getFieldList()) {
- if (!hasProperty || list.contains(fieldInfo.getProperty())) {
- Object obj = fieldInfo.thisFieldGet(t);
- if (obj != null) {
- List> joinList = MappingQuery.mpjQueryList(fieldInfo.getJoinMapper(),
- fieldInfo.isFieldIsMap(), SqlKeyword.EQ, fieldInfo.getJoinColumn(), obj, fieldInfo);
- mpjBindData(t, fieldInfo, joinList);
- fieldInfo.removeJoinField(joinList);
- }
- }
- }
- }
- return t;
- }
-
- /**
- * 查询映射关系
- * 对结果进行二次查询
- * 可以自行查询然后在通过此方法进行二次查询
- * list为null或空,会查询全部映射关系
- *
- * @param map 第一次查询结果
- */
- default Map mpjQueryMapMapping(Map map, Class clazz, List> property) {
- if (CollectionUtils.isEmpty(map)) {
- return map;
- }
- MPJTableInfo tableInfo = MPJTableInfoHelper.getTableInfo(clazz);
- if (tableInfo.isHasMappingOrField()) {
- boolean hasProperty = CollectionUtils.isNotEmpty(property);
- List list = hasProperty ? property.stream().map(LambdaUtils::getName).collect(
- Collectors.toList()) : null;
- for (MPJTableFieldInfo fieldInfo : tableInfo.getFieldList()) {
- if (!hasProperty || list.contains(fieldInfo.getProperty())) {
- Object obj = map.get(fieldInfo.getThisMapKey());
- if (obj != null) {
- List> joinList = MappingQuery.mpjQueryList(fieldInfo.getJoinMapper(),
- fieldInfo.isFieldIsMap(), SqlKeyword.EQ, fieldInfo.getJoinColumn(), obj, fieldInfo);
- mpjBindMap(map, fieldInfo, joinList);
- fieldInfo.removeJoinField(joinList);
- }
- }
- }
- }
- return map;
- }
-
- /**
- * 查询映射关系
- * 对结果进行二次查询
- * 可以自行查询然后在通过此方法进行二次查询
- * list为null或空,会查询全部映射关系
- *
- * @param list 第一次查询结果
- */
- default List mpjQueryMapping(List list, List> property) {
- if (CollectionUtils.isEmpty(list)) {
- return list;
- }
- MPJTableInfo tableInfo = MPJTableInfoHelper.getTableInfo(list.get(0).getClass());
- if (tableInfo.isHasMappingOrField()) {
- boolean hasProperty = CollectionUtils.isNotEmpty(property);
- List listProperty = hasProperty ? property.stream().map(LambdaUtils::getName).collect(
- Collectors.toList()) : null;
- for (MPJTableFieldInfo fieldInfo : tableInfo.getFieldList()) {
- if (!hasProperty || listProperty.contains(fieldInfo.getProperty())) {
- List