From f4d82318bcd3aa72f07e3b88d0b0dda11e305e39 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Wed, 30 Nov 2022 13:49:08 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../yulichang/config/MappingConfig.java | 2 +-
.../yulichang/interceptor/MPJInterceptor.java | 42 +++++++--
.../mapper/MPJTableMapperHelper.java | 12 ++-
.../yulichang/method/MPJBaseMethod.java | 6 +-
.../yulichang/query/MPJQueryWrapper.java | 30 ++++++-
.../wrapper/MPJAbstractLambdaWrapper.java | 38 ++++++--
.../yulichang/wrapper/MPJAbstractWrapper.java | 87 +++++++++++--------
.../yulichang/wrapper/MPJLambdaWrapper.java | 74 ++++++++++++----
.../wrapper/interfaces/LambdaJoin.java | 12 +--
.../wrapper/interfaces/on/OnFunction.java | 4 +-
.../wrapper/resultmap/MybatisLabel.java | 3 +
mybatis-plus-join-test/README.md | 5 ++
.../yulichang/test/collection/enums/Sex.java | 24 -----
.../yulichang/test/join/dto/TableDTO.java | 61 -------------
.../yulichang/test/join/dto/UserDTO.java | 5 +-
.../yulichang/test/join/entity/UserDO.java | 10 ++-
.../test-join/src/main/resources/db/data.sql | 44 +++++-----
.../src/main/resources/db/schema.sql | 1 +
.../test/join/LambdaWrapperTest.java | 46 ++++++++++
19 files changed, 311 insertions(+), 195 deletions(-)
create mode 100644 mybatis-plus-join-test/README.md
delete mode 100644 mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/enums/Sex.java
delete mode 100644 mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/dto/TableDTO.java
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java
index 3d8d63e..64d31fb 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java
@@ -14,7 +14,7 @@ public class MappingConfig {
public MappingConfig() {
TableInfoHelper.getTableInfos().forEach(i ->
- MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.get(i.getEntityType())));
+ MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.getMapper(i.getEntityType())));
}
}
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java
index 8a35340..0f3aba6 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.github.yulichang.interfaces.MPJBaseJoin;
+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.support.SelectColumn;
@@ -93,14 +95,26 @@ public class MPJInterceptor implements Interceptor {
/**
* 获取MappedStatement
*/
+ @SuppressWarnings("rawtypes")
public MappedStatement getMappedStatement(MappedStatement ms, Class> resultType, Object ew) {
String id = ms.getId() + StringPool.UNDERSCORE + resultType.getName();
-
- if (ew instanceof MPJLambdaWrapper && ((MPJLambdaWrapper>) ew).isResultMap()) {
+ if (ew instanceof MPJLambdaWrapper) {
+ MPJLambdaWrapper wrapper = (MPJLambdaWrapper) ew;
+ wrapper.setEntityClass(MPJTableMapperHelper.getEntity(getEntity(ms.getId())));
+ //TODO 重构缓存 -> 根据sql缓存
//不走缓存
- return buildMappedStatement(ms, resultType, ew, id);
}
- //走缓存
+ if (ew instanceof MPJQueryWrapper) {
+ MPJQueryWrapper wrapper = (MPJQueryWrapper) ew;
+ return getCache(ms, id + wrapper.getSqlSelect(), resultType, ew);
+ }
+ return buildMappedStatement(ms, resultType, ew, id);
+ }
+
+ /**
+ * 走缓存
+ */
+ private MappedStatement getCache(MappedStatement ms, String id, Class> resultType, Object ew) {
Map
* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...)
*
* @param clazz 关联实体类
* @param function 条件
*/
- default