diff --git a/README.md b/README.md index 0e1f2e1..dee4c00 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ * 对 mybatis-plus 多表查询的扩展 * 演示工程 -* 文档 +* 文档 * 点个Star支持一下吧 :) QQ群:1022221898 加入微信群 -### 文档 +### 文档 ## 使用方法 @@ -252,7 +252,7 @@ ORDER BY addr.id DESC ``` -# wiki +# wiki diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/pom.xml index 5dfc348..a10fd4f 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/pom.xml +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/pom.xml @@ -1,4 +1,5 @@ + 4.0.0 diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml new file mode 100644 index 0000000..8c22a89 --- /dev/null +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-adapter + 1.4.2.2 + + mybatis-plus-join-adapter-v352 + 1.4.2.2 + mybatis-plus-join-adapter-before352 + + An enhanced toolkit of Mybatis-Plus to simplify development. + https://github.com/yulichang/mybatis-plus-join + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + mybatis-plus-join + yulichang + yu_lichang@qq.com + + + + scm:git:https://github.com/yulichang/mybatis-plus-join.git + scm:git:https://github.com/yulichang/mybatis-plus-join.git + https://github.com/yulichang/mybatis-plus-join + + + + 1.8 + 1.8 + 1.8 + 1.8 + github + UTF-8 + + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.2 + provided + + + + diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/src/main/java/com/github/yulichang/adapter/before352/AbstractMethod352.java b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/src/main/java/com/github/yulichang/adapter/before352/AbstractMethod352.java new file mode 100644 index 0000000..913d619 --- /dev/null +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/src/main/java/com/github/yulichang/adapter/before352/AbstractMethod352.java @@ -0,0 +1,21 @@ +package com.github.yulichang.adapter.before352; + +import com.baomidou.mybatisplus.core.injector.AbstractMethod; + +/** + * @author yulichang + * @since 1.4.3 + */ +public abstract class AbstractMethod352 extends AbstractMethod { + + @Deprecated + public AbstractMethod352() { + super(); + } + + public AbstractMethod352(String methodName) { + super(methodName); + } +} + + diff --git a/mybatis-plus-join-adapter/pom.xml b/mybatis-plus-join-adapter/pom.xml index 58a606e..0e4f790 100644 --- a/mybatis-plus-join-adapter/pom.xml +++ b/mybatis-plus-join-adapter/pom.xml @@ -15,6 +15,7 @@ mybatis-plus-join-adapter-base mybatis-plus-join-adapter-v33x + mybatis-plus-join-adapter-v352 An enhanced toolkit of Mybatis-Plus to simplify development. diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index 3b4b227..d165989 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -54,10 +54,15 @@ mybatis-plus-join-adapter-v33x 1.4.2.2 + + com.github.yulichang + mybatis-plus-join-adapter-v352 + 1.4.2.2 + com.baomidou mybatis-plus-extension - 3.5.2 + 3.5.1 provided diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java index f240eec..16e8d9b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java @@ -11,8 +11,11 @@ import com.baomidou.mybatisplus.core.toolkit.ClassUtils; import com.github.yulichang.mapper.MPJTableMapperHelper; import com.github.yulichang.method.*; import com.github.yulichang.toolkit.TableHelper; +import com.github.yulichang.toolkit.VersionUtils; import com.github.yulichang.toolkit.reflect.GenericTypeUtils; import org.apache.ibatis.builder.MapperBuilderAssistant; +import org.mybatis.logging.Logger; +import org.mybatis.logging.LoggerFactory; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -33,6 +36,7 @@ import static java.util.stream.Collectors.toList; */ public class MPJSqlInjector extends DefaultSqlInjector { + private static final Logger logger = LoggerFactory.getLogger(MPJSqlInjector.class); /** * 升级到 mybatis plus 3.4.3.2 后对之前的版本兼容 @@ -40,6 +44,10 @@ public class MPJSqlInjector extends DefaultSqlInjector { @Deprecated @SuppressWarnings("unused") public List getMethodList(Class mapperClass) { + if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3.2") >= 0) { + logger.error(() -> "DefaultSqlInjector 的 getMethodList(Class mapperClass) 方法已在 3.4.3.2+ 改为" + + "getMethodList(Class mapperClass, TableInfo tableInfo)"); + } List list = Stream.of( new Insert(), new DeleteByMap(), diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java index e3ae8c0..6eb2f32 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.injector.AbstractMethod; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import com.github.yulichang.adapter.before352.AbstractMethod352; import com.github.yulichang.config.ConfigProperties; import java.util.ArrayList; @@ -13,7 +14,7 @@ import java.util.List; * @author yulichang * @see AbstractMethod */ -public abstract class MPJAbstractMethod extends AbstractMethod implements MPJBaseMethod { +public abstract class MPJAbstractMethod extends AbstractMethod352 implements MPJBaseMethod { @Deprecated diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/VersionUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/VersionUtils.java new file mode 100644 index 0000000..212b7fd --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/VersionUtils.java @@ -0,0 +1,46 @@ +package com.github.yulichang.toolkit; + +public class VersionUtils { + + public static int compare(String v1, String v2) { + String[] v1s = v1.split("\\."); + String[] v2s = v2.split("\\."); + + String[] vs = v1s.length > v2s.length ? v2s : v1s; + for (int i = 0; i < vs.length; i++) { + int compareV = compareV(v1s[i], v2s[i]); + if (compareV != 0) { + return compareV; + } + } + if (v1s.length == v2s.length) { + return 0; + } + return v1s.length > v2s.length ? 1 : -1; + } + + private static int compareV(String v1, String v2) { + if (isNumber(v1)) { + if (isNumber(v2)) { + return Integer.valueOf(v1).compareTo(Integer.valueOf(v2)); + } else { + return 1; + } + } else { + if (isNumber(v2)) { + return -1; + } else { + return v1.compareTo(v2); + } + } + } + + private static boolean isNumber(String str) { + try { + Integer.parseInt(str); + return true; + } catch (NumberFormatException e2) { + return false; + } + } +} diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index 0f79067..c55fcef 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -98,7 +98,7 @@ com.baomidou mybatis-plus-boot-starter - 3.5.2 + 3.5.3.1 org.springframework diff --git a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MPConfig.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MPConfig.java index 49da222..f3c8145 100644 --- a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MPConfig.java +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MPConfig.java @@ -51,10 +51,18 @@ // if (sql != null && s != null) { // String s1 = formatSql(sql); // String s2 = formatSql(s); -// if (StringUtils.isNotBlank(s) && !Objects.equals(s1.toLowerCase(), s2.toLowerCase())) { -// System.err.println("执行sql: " + removeExtraWhitespaces(sql)); -// System.err.println("预期sql: " + removeExtraWhitespaces(s)); -// throw new RuntimeException("sql error"); +// if (StringUtils.isNotBlank(s)) { +// if (!Objects.equals(s1.toLowerCase(), s2.toLowerCase())) { +// System.err.println("执行sql: " + removeExtraWhitespaces(sql)); +// System.err.println("预期sql: " + removeExtraWhitespaces(s)); +// throw new RuntimeException("sql error"); +// }else { +// System.out.println("==============================================="); +// System.out.println(); +// System.out.println("pass"); +// System.out.println(); +// System.out.println("==============================================="); +// } // } // } // } diff --git a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java index 97a40fa..566d2b2 100644 --- a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java @@ -47,10 +47,18 @@ public class MybatisPlusConfig { public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { String sql = boundSql.getSql(); String s = ThreadLocalUtils.get(); - if (StringUtils.isNotBlank(s) && !Objects.equals(formatSql(sql), formatSql(s))) { - System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql)); - System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s)); - throw new RuntimeException("sql error"); + if (StringUtils.isNotBlank(s)) { + if (!Objects.equals(formatSql(sql), formatSql(s))) { + System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql)); + System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s)); + throw new RuntimeException("sql error"); + } else { + System.out.println("==============================================="); + System.out.println(); + System.out.println("pass"); + System.out.println(); + System.out.println("==============================================="); + } } } @@ -63,10 +71,18 @@ public class MybatisPlusConfig { return; } String s = ThreadLocalUtils.get(); - if (StringUtils.isNotBlank(s) && !Objects.equals(formatSql(sql), formatSql(s))) { - System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql)); - System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s)); - throw new RuntimeException("sql error"); + if (StringUtils.isNotBlank(s)) { + if (!Objects.equals(formatSql(sql), formatSql(s))) { + System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql)); + System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s)); + throw new RuntimeException("sql error"); + }else { + System.out.println("==============================================="); + System.out.println(); + System.out.println("pass"); + System.out.println(); + System.out.println("==============================================="); + } } } }