diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/src/main/java/com/github/yulichang/adapter/base/IAdapter.java b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/src/main/java/com/github/yulichang/adapter/base/IAdapter.java index b0d9e97..7fe6fc5 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/src/main/java/com/github/yulichang/adapter/base/IAdapter.java +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-base/src/main/java/com/github/yulichang/adapter/base/IAdapter.java @@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo; import org.apache.ibatis.session.Configuration; +/** + * @author yulichang + * @since 1.4.3 + */ public interface IAdapter { boolean mpjHasLogic(TableInfo tableInfo); diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml new file mode 100644 index 0000000..e32ab2c --- /dev/null +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-adapter + 1.4.2.2 + + mybatis-plus-join-adapter-v33x + 1.4.2.2 + mybatis-plus-join-adapter-v33x + + 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.github.yulichang + mybatis-plus-join-adapter-base + 1.4.2.2 + + + com.baomidou + mybatis-plus-boot-starter + 3.3.0 + provided + + + diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/src/main/java/com/github/yulichang/adapter/v33x/AdapterV33x.java b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/src/main/java/com/github/yulichang/adapter/v33x/AdapterV33x.java index 48d380e..550b1b5 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/src/main/java/com/github/yulichang/adapter/v33x/AdapterV33x.java +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/src/main/java/com/github/yulichang/adapter/v33x/AdapterV33x.java @@ -8,6 +8,10 @@ import org.apache.ibatis.session.Configuration; import java.util.Objects; +/** + * @author yulichang + * @since 1.4.3 + */ public class AdapterV33x implements IAdapter { @Override diff --git a/mybatis-plus-join-adapter/pom.xml b/mybatis-plus-join-adapter/pom.xml new file mode 100644 index 0000000..58a606e --- /dev/null +++ b/mybatis-plus-join-adapter/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-root + 1.4.2.2 + + pom + 1.4.2.2 + mybatis-plus-join-adapter + mybatis-plus-join-adapter + + + mybatis-plus-join-adapter-base + mybatis-plus-join-adapter-v33x + + + 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 + + diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/adapter/Adapter.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/adapter/Adapter.java index ed3bd8f..c40e991 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/adapter/Adapter.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/adapter/Adapter.java @@ -5,6 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.github.yulichang.adapter.base.IAdapter; import org.apache.ibatis.session.Configuration; +/** + * @author yulichang + * @since 1.4.3 + */ public class Adapter implements IAdapter { @Override diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index b0ebdfb..0f79067 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -16,6 +16,7 @@ mybatis-plus-join-test + test-base test-join test-collection test-mapping @@ -97,7 +98,6 @@ com.baomidou mybatis-plus-boot-starter - 3.5.2 diff --git a/mybatis-plus-join-test/test-base/pom.xml b/mybatis-plus-join-test/test-base/pom.xml new file mode 100644 index 0000000..f46cbbf --- /dev/null +++ b/mybatis-plus-join-test/test-base/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-test + 1.4.2.2 + + test-base + 1.4.2.2 + test-base + + test-base + + + 8 + 8 + UTF-8 + + 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 new file mode 100644 index 0000000..49da222 --- /dev/null +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MPConfig.java @@ -0,0 +1,105 @@ +//package com.github.yulichang.test.config; +// +//import com.baomidou.mybatisplus.core.toolkit.StringUtils; +//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +//import com.github.yulichang.test.util.ThreadLocalUtils; +//import org.apache.ibatis.cache.CacheKey; +//import org.apache.ibatis.executor.Executor; +//import org.apache.ibatis.executor.statement.StatementHandler; +//import org.apache.ibatis.mapping.BoundSql; +//import org.apache.ibatis.mapping.MappedStatement; +//import org.apache.ibatis.plugin.*; +//import org.apache.ibatis.session.ResultHandler; +//import org.apache.ibatis.session.RowBounds; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.stereotype.Component; +// +//import java.sql.Connection; +//import java.util.Objects; +//import java.util.StringTokenizer; +// +///** +// * mp 3.3.x +// */ +//@Configuration +//public class MPConfig { +// +// @Bean +// public PaginationInterceptor mybatisPlusInterceptor() { +// return new PaginationInterceptor(); +// } +// +// @Component +// @Intercepts({ +// @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}), +// @Signature(type = StatementHandler.class, method = "getBoundSql", args = {}), +// @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}), +// @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}), +// @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}), +// }) +// public static class SqlInterceptor implements Interceptor { +// +// @Override +// public Object intercept(Invocation invocation) throws Throwable { +// Object target = invocation.getTarget(); +// BoundSql boundSql = null; +// if (target instanceof StatementHandler) { +// boundSql = ((StatementHandler) target).getBoundSql(); +// String sql = boundSql.getSql(); +// String s = ThreadLocalUtils.get(); +// 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"); +// } +// } +// } +// System.out.println(boundSql); +// return invocation.proceed(); +// } +// +// @Override +// public Object plugin(Object target) { +// if (target instanceof Executor || target instanceof StatementHandler) { +// return Plugin.wrap(target, this); +// } +// return target; +// } +// +// private String formatSql(String sql) { +// if (StringUtils.isBlank(sql)) { +// return sql; +// } +// sql = sql.replaceAll("\n", ""); +// sql = sql.replaceAll("\r", ""); +// sql = sql.replaceAll("\t", ""); +// return dg(sql); +// } +// +// private String dg(String str) { +// if (str.contains(" ")) { +// str = str.replaceAll(" ", ""); +// return dg(str); +// } +// return str; +// } +// +// private String removeExtraWhitespaces(String original) { +// StringTokenizer tokenizer = new StringTokenizer(original); +// StringBuilder builder = new StringBuilder(); +// boolean hasMoreTokens = tokenizer.hasMoreTokens(); +// while (hasMoreTokens) { +// builder.append(tokenizer.nextToken()); +// hasMoreTokens = tokenizer.hasMoreTokens(); +// if (hasMoreTokens) { +// builder.append(' '); +// } +// } +// return builder.toString(); +// } +// } +//} 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 new file mode 100644 index 0000000..97a40fa --- /dev/null +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java @@ -0,0 +1,92 @@ +package com.github.yulichang.test.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.github.yulichang.test.util.ThreadLocalUtils; +import org.apache.ibatis.builder.SqlSourceBuilder; +import org.apache.ibatis.executor.Executor; +import org.apache.ibatis.executor.statement.StatementHandler; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.session.ResultHandler; +import org.apache.ibatis.session.RowBounds; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.sql.Connection; +import java.util.Objects; + +/** + * mybatis-plus配置 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + PaginationInnerInterceptor page = new PaginationInnerInterceptor(DbType.H2); + page.setOptimizeJoin(false); + interceptor.addInnerInterceptor(page); + interceptor.addInnerInterceptor(new SqlInterceptor()); + return interceptor; + } + + /** + * 校验sql + */ + public static class SqlInterceptor implements InnerInterceptor { + + @Override + 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"); + } + } + + @Override + public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) { + BoundSql boundSql = sh.getBoundSql(); + if (boundSql != null && StringUtils.isNotBlank(boundSql.getSql())) { + String sql = boundSql.getSql(); + if (sql.toUpperCase().startsWith("SELECT")) { + 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"); + } + } + } + + private String formatSql(String sql) { + if (StringUtils.isBlank(sql)) { + return sql; + } + sql = sql.replaceAll("\n", ""); + sql = sql.replaceAll("\r", ""); + sql = sql.replaceAll("\t", ""); + return dg(sql); + } + + private String dg(String str) { + if (str.contains(" ")) { + str = str.replaceAll(" ", ""); + return dg(str); + } + return str; + } + } +} diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/util/ThreadLocalUtils.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/ThreadLocalUtils.java similarity index 90% rename from mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/util/ThreadLocalUtils.java rename to mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/ThreadLocalUtils.java index d9c1144..8253699 100644 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/util/ThreadLocalUtils.java +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/ThreadLocalUtils.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.util; +package com.github.yulichang.test.util; public class ThreadLocalUtils { diff --git a/mybatis-plus-join-test/test-collection/pom.xml b/mybatis-plus-join-test/test-collection/pom.xml index 0e383f3..07299ca 100644 --- a/mybatis-plus-join-test/test-collection/pom.xml +++ b/mybatis-plus-join-test/test-collection/pom.xml @@ -1,4 +1,5 @@ + @@ -17,4 +18,12 @@ UTF-8 + + + com.github.yulichang + test-base + 1.4.2.2 + + + diff --git a/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/Application.java b/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/Application.java index f45538c..cf5eaf6 100644 --- a/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/Application.java +++ b/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/Application.java @@ -2,8 +2,9 @@ package com.github.yulichang.test.collection; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; - +@ComponentScan(basePackages = "com.github.yulichang.test") @SpringBootApplication public class Application { diff --git a/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java b/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java deleted file mode 100644 index 2175b17..0000000 --- a/mybatis-plus-join-test/test-collection/src/main/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.yulichang.test.collection.config; - -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * mybatis-plus配置 - */ - -@Configuration -public class MybatisPlusConfig { - - /** - * 分页插件 - */ - @Bean - public MybatisPlusInterceptor paginationInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - PaginationInnerInterceptor page = new PaginationInnerInterceptor(); - interceptor.addInnerInterceptor(page); - return interceptor; - } -} diff --git a/mybatis-plus-join-test/test-join/pom.xml b/mybatis-plus-join-test/test-join/pom.xml index fc2b2be..8a99930 100644 --- a/mybatis-plus-join-test/test-join/pom.xml +++ b/mybatis-plus-join-test/test-join/pom.xml @@ -1,4 +1,5 @@ + @@ -16,4 +17,12 @@ 1.8 UTF-8 + + + + com.github.yulichang + test-base + 1.4.2.2 + + diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/Application.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/Application.java index ec86d93..98201ee 100644 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/Application.java +++ b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/Application.java @@ -2,8 +2,9 @@ package com.github.yulichang.test.join; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; - +@ComponentScan(basePackages = "com.github.yulichang.test") @SpringBootApplication public class Application { diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MPConfig.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MPConfig.java deleted file mode 100644 index ea0ddbb..0000000 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MPConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -//package com.github.yulichang.test.join.config; -// -//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -///** -// * mp 3.3.x -// */ -//@Configuration -//public class MPConfig { -// -// @Bean -// public PaginationInterceptor mybatisPlusInterceptor() { -// return new PaginationInterceptor(); -// } -//} diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java deleted file mode 100644 index 62323b3..0000000 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java +++ /dev/null @@ -1,75 +0,0 @@ -//package com.github.yulichang.test.join.config; -// -//import com.baomidou.mybatisplus.annotation.DbType; -//import com.baomidou.mybatisplus.core.toolkit.StringUtils; -//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -//import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; -//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -//import com.github.yulichang.test.join.util.ThreadLocalUtils; -//import org.apache.ibatis.builder.SqlSourceBuilder; -//import org.apache.ibatis.executor.Executor; -//import org.apache.ibatis.mapping.BoundSql; -//import org.apache.ibatis.mapping.MappedStatement; -//import org.apache.ibatis.session.ResultHandler; -//import org.apache.ibatis.session.RowBounds; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -//import java.sql.SQLException; -//import java.util.Objects; -// -///** -// * mybatis-plus配置 -// */ -//@Configuration -//public class MybatisPlusConfig { -// -// /** -// * 分页插件 -// */ -// @Bean -// public MybatisPlusInterceptor mybatisPlusInterceptor() { -// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); -// PaginationInnerInterceptor page = new PaginationInnerInterceptor(DbType.H2); -// page.setOptimizeJoin(false); -// interceptor.addInnerInterceptor(page); -// interceptor.addInnerInterceptor(new SqlInterceptor()); -// return interceptor; -// } -// -// /** -// * 校验sql -// */ -// public static class SqlInterceptor implements InnerInterceptor { -// -// @Override -// public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { -// 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"); -// } -// InnerInterceptor.super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql); -// } -// -// private String formatSql(String sql) { -// if (StringUtils.isBlank(sql)) { -// return sql; -// } -// sql = sql.replaceAll("\n", ""); -// sql = sql.replaceAll("\r", ""); -// sql = sql.replaceAll("\t", ""); -// return dg(sql); -// } -// -// private String dg(String str) { -// if (str.contains(" ")) { -// str = str.replaceAll(" ", ""); -// return dg(str); -// } -// return str; -// } -// } -//} diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java index 205e10f..3091fbd 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java @@ -12,7 +12,7 @@ import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.entity.UserDto; import com.github.yulichang.test.join.mapper.UserDTOMapper; import com.github.yulichang.test.join.mapper.UserMapper; -import com.github.yulichang.test.join.util.ThreadLocalUtils; +import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.toolkit.MPJWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.junit.jupiter.api.Test; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/UpdateWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/UpdateWrapperTest.java new file mode 100644 index 0000000..32a2023 --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/UpdateWrapperTest.java @@ -0,0 +1,69 @@ +package com.github.yulichang.test.join; + +import com.github.yulichang.test.join.entity.UserDO; +import com.github.yulichang.test.join.entity.UserDto; +import com.github.yulichang.test.join.mapper.UserDTOMapper; +import com.github.yulichang.test.join.mapper.UserMapper; +import com.github.yulichang.test.util.ThreadLocalUtils; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * springboot3 & jdk17+ + */ +@SuppressWarnings("unused") +@SpringBootTest +class UpdateWrapperTest { + @Autowired + private UserMapper userMapper; + + @Autowired + private UserDTOMapper userDTOMapper; + + + /** + * 逻辑删除 + */ + @Test + public void testUpdate() { + ThreadLocalUtils.set("UPDATE `user` t SET del=true WHERE t.del=false AND (t.id = ?)"); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .eq(UserDO::getId, 1); + + userMapper.delete(wrapper); + + assert userMapper.selectById(1) == null; + } + + /** + * 非逻辑删除 + */ + @Test + public void testUpdate1() { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.eq(UserDto::getId, 1); + userDTOMapper.delete(wrapper); + + assert userDTOMapper.selectById(1) == null; + } + + + /** + * 修改 + */ + @Test + public void testUpdate2() { +// MPJLambdaWrapper wrapper = new MPJLambdaWrapper() +// .leftJoin(UserDO.class, UserDO::getId, UserDto::getUserId) +// .eq(UserDto::getId, 1); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.eq(UserDto::getId, 1); + userDTOMapper.update(new UserDto() {{ + setUserId(2222); + }}, wrapper); + } + + +} diff --git a/mybatis-plus-join-test/test-mapping/pom.xml b/mybatis-plus-join-test/test-mapping/pom.xml index 0df61a1..1a0ce64 100644 --- a/mybatis-plus-join-test/test-mapping/pom.xml +++ b/mybatis-plus-join-test/test-mapping/pom.xml @@ -1,4 +1,5 @@ + @@ -17,4 +18,11 @@ UTF-8 + + + com.github.yulichang + test-base + 1.4.2.2 + + diff --git a/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/Application.java b/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/Application.java index ade9a3a..ac05ee2 100644 --- a/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/Application.java +++ b/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/Application.java @@ -1,7 +1,9 @@ package com.github.yulichang.test.mapping; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +@ComponentScan(basePackages = "com.github.yulichang.test") @SpringBootApplication public class Application { diff --git a/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java b/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java deleted file mode 100644 index 79685b5..0000000 --- a/mybatis-plus-join-test/test-mapping/src/main/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.yulichang.test.mapping.config; - -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * mybatis-plus配置 - */ -@Configuration -public class MybatisPlusConfig { - - /** - * 分页插件 - */ - @Bean - public MybatisPlusInterceptor paginationInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - PaginationInnerInterceptor page = new PaginationInnerInterceptor(); - interceptor.addInnerInterceptor(page); - return interceptor; - } -} diff --git a/mybatis-plus-join-test/test-springboot3-jdk17/pom.xml b/mybatis-plus-join-test/test-springboot3-jdk17/pom.xml index fb519c1..5f71f3b 100644 --- a/mybatis-plus-join-test/test-springboot3-jdk17/pom.xml +++ b/mybatis-plus-join-test/test-springboot3-jdk17/pom.xml @@ -49,6 +49,12 @@ mybatis-plus-boot-starter 3.5.3.1 + + + com.github.yulichang + test-base + 1.4.2.2 +