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
c5a1ec397e
commit
71796252ad
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
* 对 <a href="https://gitee.com/baomidou/mybatis-plus" target="_blank">mybatis-plus</a> 多表查询的扩展
|
* 对 <a href="https://gitee.com/baomidou/mybatis-plus" target="_blank">mybatis-plus</a> 多表查询的扩展
|
||||||
* <a href="https://gitee.com/best_handsome/mybatis-plus-join-demo" target="_blank">演示工程</a>
|
* <a href="https://gitee.com/best_handsome/mybatis-plus-join-demo" target="_blank">演示工程</a>
|
||||||
* <a href="https://ylctmh.com" target="_blank">文档</a>
|
* <a href="https://www.baidu.com/link?url=cknmzNRg3E2p9d0BbUuQ2MBYCSSs6u1LCtNm5RzIzui&wd=&eqid=a5bbe908000085540000000563f830c5" target="_blank">文档</a>
|
||||||
* 点个Star支持一下吧 :)
|
* 点个Star支持一下吧 :)
|
||||||
|
|
||||||
QQ群:1022221898
|
QQ群:1022221898
|
||||||
<a href="https://gitee.com/best_handsome/mybatis-plus-join/issues/I65N2M" target="_blank">加入微信群</a>
|
<a href="https://gitee.com/best_handsome/mybatis-plus-join/issues/I65N2M" target="_blank">加入微信群</a>
|
||||||
|
|
||||||
### <a href="https://ylctmh.com" target="_blank">文档</a>
|
### <a href="https://www.baidu.com/link?url=cknmzNRg3E2p9d0BbUuQ2MBYCSSs6u1LCtNm5RzIzui&wd=&eqid=a5bbe908000085540000000563f830c5" target="_blank">文档</a>
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ ORDER BY
|
|||||||
addr.id DESC
|
addr.id DESC
|
||||||
```
|
```
|
||||||
|
|
||||||
# <a href="https://ylctmh.com" target="_blank">wiki</a>
|
# <a href="https://www.baidu.com/link?url=cknmzNRg3E2p9d0BbUuQ2MBYCSSs6u1LCtNm5RzIzui&wd=&eqid=a5bbe908000085540000000563f830c5" target="_blank">wiki</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--suppress ALL -->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
|
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter</artifactId>
|
||||||
|
<version>1.4.2.2</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-v352</artifactId>
|
||||||
|
<version>1.4.2.2</version>
|
||||||
|
<name>mybatis-plus-join-adapter-before352</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.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>mybatis-plus-join-adapter-base</module>
|
<module>mybatis-plus-join-adapter-base</module>
|
||||||
<module>mybatis-plus-join-adapter-v33x</module>
|
<module>mybatis-plus-join-adapter-v33x</module>
|
||||||
|
<module>mybatis-plus-join-adapter-v352</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
|
@ -54,10 +54,15 @@
|
|||||||
<artifactId>mybatis-plus-join-adapter-v33x</artifactId>
|
<artifactId>mybatis-plus-join-adapter-v33x</artifactId>
|
||||||
<version>1.4.2.2</version>
|
<version>1.4.2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-v352</artifactId>
|
||||||
|
<version>1.4.2.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-extension</artifactId>
|
<artifactId>mybatis-plus-extension</artifactId>
|
||||||
<version>3.5.2</version>
|
<version>3.5.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -11,8 +11,11 @@ import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
|||||||
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
import com.github.yulichang.mapper.MPJTableMapperHelper;
|
||||||
import com.github.yulichang.method.*;
|
import com.github.yulichang.method.*;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
|
import com.github.yulichang.toolkit.VersionUtils;
|
||||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
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.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@ -33,6 +36,7 @@ import static java.util.stream.Collectors.toList;
|
|||||||
*/
|
*/
|
||||||
public class MPJSqlInjector extends DefaultSqlInjector {
|
public class MPJSqlInjector extends DefaultSqlInjector {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MPJSqlInjector.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 升级到 mybatis plus 3.4.3.2 后对之前的版本兼容
|
* 升级到 mybatis plus 3.4.3.2 后对之前的版本兼容
|
||||||
@ -40,6 +44,10 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
|
public List<AbstractMethod> 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<AbstractMethod> list = Stream.of(
|
List<AbstractMethod> list = Stream.of(
|
||||||
new Insert(),
|
new Insert(),
|
||||||
new DeleteByMap(),
|
new DeleteByMap(),
|
||||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||||
|
import com.github.yulichang.adapter.before352.AbstractMethod352;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -13,7 +14,7 @@ import java.util.List;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @see AbstractMethod
|
* @see AbstractMethod
|
||||||
*/
|
*/
|
||||||
public abstract class MPJAbstractMethod extends AbstractMethod implements MPJBaseMethod {
|
public abstract class MPJAbstractMethod extends AbstractMethod352 implements MPJBaseMethod {
|
||||||
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -98,7 +98,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
<version>3.5.2</version>
|
<version>3.5.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
@ -51,10 +51,18 @@
|
|||||||
// if (sql != null && s != null) {
|
// if (sql != null && s != null) {
|
||||||
// String s1 = formatSql(sql);
|
// String s1 = formatSql(sql);
|
||||||
// String s2 = formatSql(s);
|
// String s2 = formatSql(s);
|
||||||
// if (StringUtils.isNotBlank(s) && !Objects.equals(s1.toLowerCase(), s2.toLowerCase())) {
|
// if (StringUtils.isNotBlank(s)) {
|
||||||
// System.err.println("执行sql: " + removeExtraWhitespaces(sql));
|
// if (!Objects.equals(s1.toLowerCase(), s2.toLowerCase())) {
|
||||||
// System.err.println("预期sql: " + removeExtraWhitespaces(s));
|
// System.err.println("执行sql: " + removeExtraWhitespaces(sql));
|
||||||
// throw new RuntimeException("sql error");
|
// 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("===============================================");
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -47,10 +47,18 @@ public class MybatisPlusConfig {
|
|||||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
|
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
|
||||||
String sql = boundSql.getSql();
|
String sql = boundSql.getSql();
|
||||||
String s = ThreadLocalUtils.get();
|
String s = ThreadLocalUtils.get();
|
||||||
if (StringUtils.isNotBlank(s) && !Objects.equals(formatSql(sql), formatSql(s))) {
|
if (StringUtils.isNotBlank(s)) {
|
||||||
System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql));
|
if (!Objects.equals(formatSql(sql), formatSql(s))) {
|
||||||
System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s));
|
System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql));
|
||||||
throw new RuntimeException("sql error");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
String s = ThreadLocalUtils.get();
|
String s = ThreadLocalUtils.get();
|
||||||
if (StringUtils.isNotBlank(s) && !Objects.equals(formatSql(sql), formatSql(s))) {
|
if (StringUtils.isNotBlank(s)) {
|
||||||
System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql));
|
if (!Objects.equals(formatSql(sql), formatSql(s))) {
|
||||||
System.err.println("预期sql: " + SqlSourceBuilder.removeExtraWhitespaces(s));
|
System.err.println("执行sql: " + SqlSourceBuilder.removeExtraWhitespaces(sql));
|
||||||
throw new RuntimeException("sql error");
|
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("===============================================");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user