mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
feat: wrapper ext
This commit is contained in:
parent
720934500f
commit
effdc96299
@ -64,6 +64,11 @@
|
|||||||
<artifactId>mybatis-plus-join-adapter-v355</artifactId>
|
<artifactId>mybatis-plus-join-adapter-v355</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-wrapper-ext</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-extension</artifactId>
|
<artifactId>mybatis-plus-extension</artifactId>
|
||||||
@ -99,5 +104,19 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -3,6 +3,7 @@ package com.github.yulichang.config;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||||
import com.github.yulichang.toolkit.InterceptorList;
|
import com.github.yulichang.toolkit.InterceptorList;
|
||||||
|
import com.github.yulichang.toolkit.MybatisJoinPlusVersion;
|
||||||
import org.apache.ibatis.logging.Log;
|
import org.apache.ibatis.logging.Log;
|
||||||
import org.apache.ibatis.logging.LogFactory;
|
import org.apache.ibatis.logging.LogFactory;
|
||||||
import org.apache.ibatis.plugin.Interceptor;
|
import org.apache.ibatis.plugin.Interceptor;
|
||||||
@ -30,7 +31,7 @@ public class MPJInterceptorConfig {
|
|||||||
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
|
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
|
||||||
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
|
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
|
||||||
" / | /\n" +
|
" / | /\n" +
|
||||||
" 1.5.2-SNAPSHOT");
|
" " + MybatisJoinPlusVersion.getVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.github.yulichang.toolkit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.security.CodeSource;
|
||||||
|
import java.util.jar.Attributes;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy {@link com.baomidou.mybatisplus.core.MybatisPlusVersion}
|
||||||
|
*
|
||||||
|
* @since 1.5.2
|
||||||
|
*/
|
||||||
|
public class MybatisJoinPlusVersion {
|
||||||
|
|
||||||
|
private MybatisJoinPlusVersion() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return determineSpringBootVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String determineSpringBootVersion() {
|
||||||
|
final Package pkg = MybatisJoinPlusVersion.class.getPackage();
|
||||||
|
if (pkg != null && pkg.getImplementationVersion() != null) {
|
||||||
|
return pkg.getImplementationVersion();
|
||||||
|
}
|
||||||
|
CodeSource codeSource = MybatisJoinPlusVersion.class.getProtectionDomain().getCodeSource();
|
||||||
|
if (codeSource == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
URL codeSourceLocation = codeSource.getLocation();
|
||||||
|
try {
|
||||||
|
URLConnection connection = codeSourceLocation.openConnection();
|
||||||
|
if (connection instanceof JarURLConnection) {
|
||||||
|
return getImplementationVersion(((JarURLConnection) connection).getJarFile());
|
||||||
|
}
|
||||||
|
try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
|
||||||
|
return getImplementationVersion(jarFile);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getImplementationVersion(JarFile jarFile) throws IOException {
|
||||||
|
return jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@ import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
|||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.*;
|
||||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||||
|
import com.github.yulichang.wrapper.ext.Ext;
|
||||||
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
||||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||||
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
||||||
@ -40,7 +41,7 @@ import static java.util.stream.Collectors.joining;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"DuplicatedCode", "unused"})
|
@SuppressWarnings({"DuplicatedCode", "unused"})
|
||||||
public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstractLambdaWrapper<T, Children>>
|
public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstractLambdaWrapper<T, Children>>
|
||||||
extends JoinAbstractWrapper<T, Children> implements QueryJoin<Children, T> {
|
extends JoinAbstractWrapper<T, Children> implements QueryJoin<Children, T>, Ext<Children> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否存在对一或对多
|
* 是否存在对一或对多
|
||||||
|
@ -2,11 +2,13 @@ package com.github.yulichang.wrapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.*;
|
||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
|
||||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.*;
|
import com.github.yulichang.wrapper.interfaces.*;
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param <Children> wrapper
|
||||||
|
* @auther yulichang
|
||||||
|
* @since 1.5.2
|
||||||
|
*/
|
||||||
|
public interface IExt<Children extends MPJLambdaWrapper<?>> {
|
||||||
|
|
||||||
|
Children getChildren();
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,17 @@
|
|||||||
<artifactId>test-join</artifactId>
|
<artifactId>test-join</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-wrapper-ext</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.yulichang</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>test-base</artifactId>
|
<artifactId>test-base</artifactId>
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.yulichang.wrapper.ext;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.IExt;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface Ext<Children extends MPJLambdaWrapper<?>> extends IExt<Children> {
|
||||||
|
|
||||||
|
default <T, R> Children cccEq(SFunction<T, ?> c, Object val) {
|
||||||
|
getChildren().eq(c, val);
|
||||||
|
return getChildren();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.github.yulichang.test.join.unit;
|
||||||
|
|
||||||
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
|
import com.github.yulichang.test.util.Reset;
|
||||||
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
|
import com.github.yulichang.toolkit.JoinWrappers;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class ExtWrapperTest {
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
Reset.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyFunc() {
|
||||||
|
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, " +
|
||||||
|
"t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||||
|
"t.address_id2, t.del, t.create_by, t.update_by " +
|
||||||
|
"FROM `user` t WHERE t.del = false AND (t.id = ?)");
|
||||||
|
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||||
|
.selectAll()
|
||||||
|
.cccEq(UserDO::getId, 1);
|
||||||
|
wrapper.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
<version>${revision}</version>
|
||||||
|
|
||||||
<artifactId>mybatis-plus-join-solon-plugin</artifactId>
|
<artifactId>mybatis-plus-join-solon-plugin</artifactId>
|
||||||
|
|
||||||
|
16
plugin/mybatis-plus-join-wrapper-ext/pom.xml
Normal file
16
plugin/mybatis-plus-join-wrapper-ext/pom.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?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>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<version>${revision}</version>
|
||||||
|
|
||||||
|
<artifactId>mybatis-plus-join-wrapper-ext</artifactId>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.github.yulichang.wrapper.ext;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义Wrapper扩展
|
||||||
|
*
|
||||||
|
* @param <Wrapper> wrapper 一般是指 MPJLambdaWrapper
|
||||||
|
* @auther yulichang
|
||||||
|
* @since 1.5.2
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface Ext<Wrapper> {
|
||||||
|
}
|
1
pom.xml
1
pom.xml
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
<module>plugin/mybatis-plus-join-solon-plugin</module>
|
<module>plugin/mybatis-plus-join-solon-plugin</module>
|
||||||
<module>plugin/mybatis-plus-join-processor</module>
|
<module>plugin/mybatis-plus-join-processor</module>
|
||||||
|
<module>plugin/mybatis-plus-join-wrapper-ext</module>
|
||||||
|
|
||||||
<module>mybatis-plus-join-test</module>
|
<module>mybatis-plus-join-test</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user