test: 完善测试代码

This commit is contained in:
yulichang 2024-05-28 05:01:33 +08:00
parent e93fbe968f
commit fddb12b943
19 changed files with 651 additions and 71 deletions

View File

@ -2,14 +2,16 @@ package com.github.yulichang.interceptor;
import com.baomidou.mybatisplus.core.MybatisPlusVersion; import com.baomidou.mybatisplus.core.MybatisPlusVersion;
import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.adapter.AdapterHelper;
import com.github.yulichang.adapter.base.tookit.VersionUtils; import com.github.yulichang.adapter.base.tookit.VersionUtils;
import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.query.MPJQueryWrapper; import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.toolkit.*; import com.github.yulichang.toolkit.*;
import com.github.yulichang.toolkit.ReflectionKit;
import com.github.yulichang.toolkit.support.FieldCache; import com.github.yulichang.toolkit.support.FieldCache;
import com.github.yulichang.wrapper.interfaces.SelectWrapper; import com.github.yulichang.wrapper.interfaces.SelectWrapper;
import com.github.yulichang.wrapper.resultmap.IResult; import com.github.yulichang.wrapper.resultmap.IResult;

View File

@ -7,9 +7,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.adapter.AdapterHelper;
import com.github.yulichang.toolkit.*;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.ReflectionKit; import com.github.yulichang.toolkit.ReflectionKit;
import com.github.yulichang.toolkit.*;
import com.github.yulichang.wrapper.interfaces.Update; import com.github.yulichang.wrapper.interfaces.Update;
import com.github.yulichang.wrapper.interfaces.UpdateChain; import com.github.yulichang.wrapper.interfaces.UpdateChain;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.ISqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn; import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
import com.github.yulichang.injector.MPJSqlInjector; import com.github.yulichang.injector.MPJSqlInjector;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@ -22,6 +24,7 @@ import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.statement.StatementHandler; import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -33,6 +36,8 @@ import org.springframework.core.annotation.Order;
import java.sql.Connection; import java.sql.Connection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
/** /**
* mybatis-plus配置 * mybatis-plus配置
@ -46,7 +51,7 @@ public class MybatisPlusConfig {
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor page = new PaginationInnerInterceptor(DbType.H2); PaginationInnerInterceptor page = new PaginationInnerInterceptor();
page.setOptimizeJoin(false); page.setOptimizeJoin(false);
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() { interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
@Override @Override
@ -93,10 +98,22 @@ public class MybatisPlusConfig {
*/ */
public static class SqlInterceptor implements InnerInterceptor { public static class SqlInterceptor implements InnerInterceptor {
private DbType dbType;
private static final Predicate<DbType> P = type -> type == DbType.POSTGRE_SQL || type == DbType.ORACLE;
@Override @Override
@SneakyThrows @SneakyThrows
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();
this.dbType = Optional.ofNullable(this.dbType).orElse(JdbcUtils.getDbType(executor));
if (P.test(this.dbType)) {
PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
mpBoundSql.sql(sql.replaceAll("`", "\""));
mpBoundSql.parameterMappings(mappings);
}
check(sql); check(sql);
} }
@ -123,6 +140,13 @@ public class MybatisPlusConfig {
BoundSql boundSql = sh.getBoundSql(); BoundSql boundSql = sh.getBoundSql();
if (boundSql != null && StringUtils.isNotBlank(boundSql.getSql())) { if (boundSql != null && StringUtils.isNotBlank(boundSql.getSql())) {
String sql = boundSql.getSql(); String sql = boundSql.getSql();
this.dbType = Optional.ofNullable(this.dbType).orElse(JdbcUtils.getDbType(connection.getMetaData().getURL()));
if (P.test(this.dbType)) {
PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
mpBoundSql.sql(sql.replaceAll("`", "\""));
mpBoundSql.parameterMappings(mappings);
}
if (sql.toUpperCase().startsWith("SELECT")) { if (sql.toUpperCase().startsWith("SELECT")) {
return; return;
} }
@ -137,6 +161,10 @@ public class MybatisPlusConfig {
sql = sql.replaceAll("\n", ""); sql = sql.replaceAll("\n", "");
sql = sql.replaceAll("\r", ""); sql = sql.replaceAll("\r", "");
sql = sql.replaceAll("\t", ""); sql = sql.replaceAll("\t", "");
if (P.test(this.dbType)) {
sql = sql.replaceAll("\"", "`");
sql = sql.replaceAll("`", "");
}
return dg(sql); return dg(sql);
} }

View File

@ -0,0 +1,26 @@
package com.github.yulichang.test.util;
import com.baomidou.mybatisplus.annotation.DbType;
import java.util.Arrays;
public enum DbTypeEnum {
H2(DbType.H2, ""),
MYSQL(DbType.MYSQL, ""),
POSTGRE_SQL(DbType.POSTGRE_SQL, "pgsql/"),
ORACLE(DbType.ORACLE, "oracle/");
private final DbType dbType;
private final String path;
DbTypeEnum(DbType dbType, String path) {
this.dbType = dbType;
this.path = path;
}
public static String getPath(DbType dbType) {
return Arrays.stream(DbTypeEnum.values()).filter(e -> e.dbType == dbType).findFirst().map(e -> e.path).orElse("");
}
}

View File

@ -0,0 +1,23 @@
package com.github.yulichang.test.util;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
import com.github.yulichang.toolkit.SpringContentUtils;
import org.springframework.core.env.Environment;
import java.util.Optional;
public class DbTypeUtil {
private static DbType dbType;
public static DbType getDbType() {
return Optional.ofNullable(dbType).orElseGet(() -> {
String jdbcUrl = SpringContentUtils.getBean(Environment.class).getProperty("spring.datasource.url");
assert jdbcUrl != null;
DbType type = JdbcUtils.getDbType(jdbcUrl);
dbType = type;
return type;
});
}
}

View File

@ -1,5 +1,7 @@
package com.github.yulichang.test.util; package com.github.yulichang.test.util;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
import com.github.yulichang.toolkit.SpringContentUtils; import com.github.yulichang.toolkit.SpringContentUtils;
import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -7,6 +9,8 @@ import org.mybatis.spring.SqlSessionTemplate;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.SQLException;
public class Reset { public class Reset {
@ -14,12 +18,21 @@ public class Reset {
public static void reset() { public static void reset() {
SqlSession session = SpringContentUtils.getBean(SqlSessionTemplate.class) SqlSession session = SpringContentUtils.getBean(SqlSessionTemplate.class)
.getSqlSessionFactory().openSession(true); .getSqlSessionFactory().openSession(true);
ScriptRunner runner = new ScriptRunner(session.getConnection()); Connection connection = session.getConnection();
ScriptRunner runner = new ScriptRunner(connection);
String path = "db/";
try {
DbType dbType = JdbcUtils.getDbType(connection.getMetaData().getURL());
path += DbTypeEnum.getPath(dbType);
} catch (SQLException e) {
throw new RuntimeException(e);
}
runner.setLogWriter(null); runner.setLogWriter(null);
runner.runScript(new InputStreamReader( runner.runScript(new InputStreamReader(
Reset.class.getClassLoader().getResourceAsStream("db/schema.sql"), StandardCharsets.UTF_8)); Reset.class.getClassLoader().getResourceAsStream(path + "schema.sql"), StandardCharsets.UTF_8));
runner.runScript(new InputStreamReader( runner.runScript(new InputStreamReader(
Reset.class.getClassLoader().getResourceAsStream("db/data.sql"), StandardCharsets.UTF_8)); Reset.class.getClassLoader().getResourceAsStream(path + "data.sql"), StandardCharsets.UTF_8));
session.commit(); session.commit();
session.close(); session.close();
} }

View File

@ -0,0 +1,42 @@
package com.github.yulichang.test.util;
import com.baomidou.mybatisplus.annotation.DbType;
import org.springframework.jdbc.BadSqlGrammarException;
import java.util.Arrays;
public class Throw {
public static void tryDo(DoSomething doSomething) {
try {
doSomething.doSomething();
} catch (BadSqlGrammarException e) {
if (DbTypeUtil.getDbType() != DbType.H2) {
throw e;
}
}
}
public static void tryDo(DoSomething doSomething, DbType... ignore) {
try {
doSomething.doSomething();
} catch (BadSqlGrammarException e) {
if (DbTypeUtil.getDbType() != DbType.H2 && Arrays.stream(ignore).noneMatch(n -> n == DbTypeUtil.getDbType())) {
throw e;
}
}
}
public static void tryDoIgnore(DoSomething doSomething) {
try {
doSomething.doSomething();
} catch (BadSqlGrammarException ignore) {
}
}
@FunctionalInterface
public interface DoSomething {
void doSomething();
}
}

View File

@ -27,7 +27,14 @@
<dependency> <dependency>
<groupId>com.mysql</groupId> <groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>8.0.32</version> </dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>

View File

@ -1,15 +1,7 @@
#file: noinspection SpringBootApplicationYaml #file: noinspection SpringBootApplicationYaml
spring: spring:
datasource: profiles:
driver-class-name: org.h2.Driver active: h2
url: jdbc:h2:mem:test
username: root
password: test
# datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/mpj_test
# username: root
# password: 123456
sql: sql:
init: init:
schema-locations: classpath:db/schema.sql schema-locations: classpath:db/schema.sql
@ -32,3 +24,44 @@ mybatis-plus-join:
sub-table-logic: true sub-table-logic: true
ms-cache: true ms-cache: true
logic-del-type: where logic-del-type: where
---
spring:
profiles: h2
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test
username: root
password: test
---
spring:
profiles: mysql
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mpj_test
username: root
password: 123456
---
spring:
profiles: pgsql
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/mpj_test
username: postgres
password: 123456
sql:
init:
schema-locations: classpath:db/pgsql/schema.sql
data-locations: classpath:db/pgsql/data.sql
---
spring:
profiles: oracle
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@//localhost:1521/FREE
username: sys as sysdba
password: 123456
sql:
init:
schema-locations: classpath:db/oracle/schema.sql
data-locations: classpath:db/oracle/data.sql

View File

@ -0,0 +1,119 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
DELETE FROM area;
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10001, '北京市01', '北京01', '朝阳01', '80001', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10002, '北京市02', '北京02', '朝阳02', '80002', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10003, '北京市03', '北京03', '朝阳03', '80003', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10004, '北京市04', '北京04', '朝阳04', '80004', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10005, '北京市05', '北京05', '朝阳05', '80005', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10006, '北京市06', '北京06', '朝阳06', '80006', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10007, '北京市07', '北京07', '朝阳07', '80007', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10008, '北京市08', '北京08', '朝阳08', '80008', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10009, '北京市09', '北京09', '朝阳09', '80009', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10010, '北京市10', '北京10', '朝阳10', '80010', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10011, '北京市11', '北京11', '朝阳11', '80011', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10012, '北京市12', '北京12', '朝阳12', '80012', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10013, '北京市13', '北京13', '朝阳13', '80013', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10014, '北京市14', '北京14', '朝阳14', '80014', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10015, '北京市15', '北京15', '朝阳15', '80015', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10016, '北京市16', '北京16', '朝阳16', '80016', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10017, '北京市17', '北京17', '朝阳17', '80017', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10018, '北京市18', '北京18', '朝阳18', '80018', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10019, '北京市19', '北京19', '朝阳19', '80019', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10020, '北京市20', '北京20', '朝阳20', '80020', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10021, '北京市21', '北京21', '朝阳21', '80021', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10022, '北京市22', '北京22', '朝阳22', '80022', false);
DELETE FROM "user";
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 1, 1, '张三 1', '{"id": 1,"name":"张三 1"}', 1, 2, 1, 'https://url-01', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 2, 1, '张三 2', '{"id": 2,"name":"张三 2"}', 1, 2, 0, 'https://url-02', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 2, 3, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 3, 1, '张三 3', '{"id": 3,"name":"张三 3"}', 1, 2, 0, 'https://url-03', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 3, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 4, 1, '张三 4', '{"id": 4,"name":"张三 4"}', 1, 2, 0, 'https://url-04', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 9, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 5, 1, '张三 5', '{"id": 5,"name":"张三 5"}', 1, 2, 0, 'https://url-05', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 6, 1, '张三 6', '{"id": 6,"name":"张三 6"}', 1, 2, 0, 'https://url-06', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 7, 1, '张三 7', '{"id": 7,"name":"张三 7"}', 1, 2, 0, 'https://url-07', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 8, 1, '张三 8', '{"id": 8,"name":"张三 8"}', 1, 2, 0, 'https://url-08', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES ( 9, 1, '张三 9', '{"id": 9,"name":"张三 9"}', 1, 2, 0, 'https://url-09', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (10, 1, '张三10', '{"id":10,"name":"张三10"}', 1, 2, 0, 'https://url-10', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (11, 1, '张三11', '{"id":11,"name":"张三11"}', 1, 2, 0, 'https://url-11', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (12, 1, '张三12', '{"id":12,"name":"张三12"}', 1, 2, 0, 'https://url-12', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (13, 1, '张三13', '{"id":13,"name":"张三13"}', 1, 2, 0, 'https://url-13', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (14, 2, '张三14', '{"id":14,"name":"张三14"}', 1, 2, 0, 'https://url-14', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (15, 2, '张三15', '{"id":15,"name":"张三15"}', 1, 2, 0, 'https://url-15', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (16, 2, '张三16', '{"id":16,"name":"张三16"}', 1, 2, 0, 'https://url-16', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (17, 2, '张三17', '{"id":17,"name":"张三17"}', 1, 2, 0, 'https://url-17', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (18, 2, '张三18', '{"id":18,"name":"张三18"}', 1, 2, 0, 'https://url-18', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, false);
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (19, 2, '张三19', '{"id":19,"name":"张三19"}', 1, 2, 0, 'https://url-19', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (20, 2, '张三20', '{"id":20,"name":"张三20"}', 1, 2, 0, 'https://url-20', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (21, 2, '张三21', '{"id":21,"name":"张三21"}', 1, 2, 0, 'https://url-21', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
INSERT INTO "user" (id, pid, "name", "json", address_id, address_id2 , sex, head_img, create_time, create_by, update_by, del) VALUES (22, 2, '张三22', '{"id":22,"name":"张三22"}', 1, 2, 0, 'https://url-22', TO_TIMESTAMP('2022-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, true );
DELETE FROM address;
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 1, 1, 10001, '10000000001', '朝阳01', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 2, 1, 10002, '10000000002', '朝阳02', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 3, 1, 10003, '10000000003', '朝阳03', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 4, 1, 10004, '10000000004', '朝阳04', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 5, 1, 10005, '10000000005', '朝阳05', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 6, 1, 10006, '10000000006', '朝阳06', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 7, 1, 10007, '10000000007', '朝阳07', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 8, 1, 10008, '10000000008', '朝阳08', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 9, 1, 10009, '10000000009', '朝阳09', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (10,10, 10010, '10000000010', '朝阳10', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (11,11, 10011, '10000000011', '朝阳11', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (12,12, 10012, '10000000012', '朝阳12', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (13,13, 10013, '10000000013', '朝阳13', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (14,14, 10014, '10000000014', '朝阳14', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (15,15, 10015, '10000000015', '朝阳15', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (16,16, 10016, '10000000016', '朝阳16', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (17,17, 10017, '10000000017', '朝阳17', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (18,18, 10018, '10000000018', '朝阳18', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (19,19, 10019, '10000000019', '朝阳19', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (20,20, 10020, '10000000020', '朝阳20', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (21,21, 10021, '10000000021', '朝阳21', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '朝阳22', false);
DELETE FROM user_dto;
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (1,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (2,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (3,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (4,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (5,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (6,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (7,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (8,1, 2, 3, false);
DELETE FROM order_t;
INSERT INTO order_t (id, user_id, age, name) VALUES (1, 1, 8, '1,8');
INSERT INTO order_t (id, user_id, age, name) VALUES (2, 2, 7, '2,7');
INSERT INTO order_t (id, user_id, age, name) VALUES (3, 3, 6, '3,6');
INSERT INTO order_t (id, user_id, age, name) VALUES (4, 4, 5, '4,5');
INSERT INTO order_t (id, user_id, age, name) VALUES (5, 5, 4, '5,4');
INSERT INTO order_t (id, user_id, age, name) VALUES (6, 6, 3, '6,3');
INSERT INTO order_t (id, user_id, age, name) VALUES (7, 7, 2, '7,2');
INSERT INTO order_t (id, user_id, age, name) VALUES (8, 8, 1, '8,1');
DELETE FROM user_tenant;
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (1, 1, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (2, 2, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (3, 3, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (4, 4, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (5, 5, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (6, 6, 2);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (7, 7, 2);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (8, 8, 2);
DELETE FROM user_tenanta;
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (1, 1, 1, '中文字段1');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (2, 2, 1, '中文字段2');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (3, 3, 1, '中文字段3');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (4, 4, 1, '中文字段4');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (5, 5, 1, '中文字段5');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (6, 6, 2, '中文字段6');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (7, 7, 2, '中文字段7');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (8, 8, 2, '中文字段8');

View File

@ -0,0 +1,85 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
DROP TABLE IF EXISTS area;
create table area
(
id int
primary key,
province varchar(255) null,
city varchar(255) null,
area varchar(255) null,
postcode varchar(255) null,
del boolean
);
DROP TABLE IF EXISTS "user";
create table "user"
(
id int
primary key,
pid int null,
"name" varchar(255) null,
"json" varchar(255) null,
address_id int null,
address_id2 int null,
sex int null,
head_img varchar(255) null,
create_time timestamp null,
create_by int null,
update_by int null,
del boolean
);
DROP TABLE IF EXISTS address;
create table address
(
id int
primary key,
user_id int null,
area_id int null,
tel varchar(255) null,
address varchar(255) null,
del boolean
);
DROP TABLE IF EXISTS user_dto;
create table user_dto
(
id int
primary key,
user_id int null,
create_by int null,
update_by int null,
del boolean null
);
DROP TABLE IF EXISTS order_t;
create table order_t
(
id int
primary key,
user_id int null,
age int null,
name varchar(255) null
);
DROP TABLE IF EXISTS user_tenant;
create table user_tenant
(
id int
primary key,
user_id int null,
tenant_id int null
);
DROP TABLE IF EXISTS user_tenanta;
create table user_tenanta
(
id int
primary key,
user_id int null,
tenant_id int null,
varchar(255) null
);

View File

@ -0,0 +1,119 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
DELETE FROM area;
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10001, '北京市01', '北京01', '朝阳01', '80001', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10002, '北京市02', '北京02', '朝阳02', '80002', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10003, '北京市03', '北京03', '朝阳03', '80003', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10004, '北京市04', '北京04', '朝阳04', '80004', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10005, '北京市05', '北京05', '朝阳05', '80005', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10006, '北京市06', '北京06', '朝阳06', '80006', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10007, '北京市07', '北京07', '朝阳07', '80007', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10008, '北京市08', '北京08', '朝阳08', '80008', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10009, '北京市09', '北京09', '朝阳09', '80009', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10010, '北京市10', '北京10', '朝阳10', '80010', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10011, '北京市11', '北京11', '朝阳11', '80011', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10012, '北京市12', '北京12', '朝阳12', '80012', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10013, '北京市13', '北京13', '朝阳13', '80013', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10014, '北京市14', '北京14', '朝阳14', '80014', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10015, '北京市15', '北京15', '朝阳15', '80015', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10016, '北京市16', '北京16', '朝阳16', '80016', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10017, '北京市17', '北京17', '朝阳17', '80017', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10018, '北京市18', '北京18', '朝阳18', '80018', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10019, '北京市19', '北京19', '朝阳19', '80019', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10020, '北京市20', '北京20', '朝阳20', '80020', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10021, '北京市21', '北京21', '朝阳21', '80021', false);
INSERT INTO area (id, province, city, area, postcode, del) VALUES (10022, '北京市22', '北京22', '朝阳22', '80022', false);
DELETE FROM "user";
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 1, 1, '张三 1', '{"id": 1,"name":"张三 1"}', 1, 2, 1, 'https://url-01', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 2, 1, '张三 2', '{"id": 2,"name":"张三 2"}', 1, 2, 0, 'https://url-02', '2022-01-01 12:00:00', 2, 3, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 3, 1, '张三 3', '{"id": 3,"name":"张三 3"}', 1, 2, 0, 'https://url-03', '2022-01-01 12:00:00', 3, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 4, 1, '张三 4', '{"id": 4,"name":"张三 4"}', 1, 2, 0, 'https://url-04', '2022-01-01 12:00:00', 9, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 5, 1, '张三 5', '{"id": 5,"name":"张三 5"}', 1, 2, 0, 'https://url-05', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 6, 1, '张三 6', '{"id": 6,"name":"张三 6"}', 1, 2, 0, 'https://url-06', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 7, 1, '张三 7', '{"id": 7,"name":"张三 7"}', 1, 2, 0, 'https://url-07', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 8, 1, '张三 8', '{"id": 8,"name":"张三 8"}', 1, 2, 0, 'https://url-08', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES ( 9, 1, '张三 9', '{"id": 9,"name":"张三 9"}', 1, 2, 0, 'https://url-09', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (10, 1, '张三10', '{"id":10,"name":"张三10"}', 1, 2, 0, 'https://url-10', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (11, 1, '张三11', '{"id":11,"name":"张三11"}', 1, 2, 0, 'https://url-11', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (12, 1, '张三12', '{"id":12,"name":"张三12"}', 1, 2, 0, 'https://url-12', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (13, 1, '张三13', '{"id":13,"name":"张三13"}', 1, 2, 0, 'https://url-13', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (14, 2, '张三14', '{"id":14,"name":"张三14"}', 1, 2, 0, 'https://url-14', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (15, 2, '张三15', '{"id":15,"name":"张三15"}', 1, 2, 0, 'https://url-15', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (16, 2, '张三16', '{"id":16,"name":"张三16"}', 1, 2, 0, 'https://url-16', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (17, 2, '张三17', '{"id":17,"name":"张三17"}', 1, 2, 0, 'https://url-17', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (18, 2, '张三18', '{"id":18,"name":"张三18"}', 1, 2, 0, 'https://url-18', '2022-01-01 12:00:00', 1, 2, false);
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (19, 2, '张三19', '{"id":19,"name":"张三19"}', 1, 2, 0, 'https://url-19', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (20, 2, '张三20', '{"id":20,"name":"张三20"}', 1, 2, 0, 'https://url-20', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (21, 2, '张三21', '{"id":21,"name":"张三21"}', 1, 2, 0, 'https://url-21', '2022-01-01 12:00:00', 1, 2, true );
INSERT INTO "user" (id, "pid", "name", "json", "address_id", "address_id2" , sex, head_img, create_time, create_by, update_by, del) VALUES (22, 2, '张三22', '{"id":22,"name":"张三22"}', 1, 2, 0, 'https://url-22', '2022-01-01 12:00:00', 1, 2, true );
DELETE FROM address;
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 1, 1, 10001, '10000000001', '朝阳01', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 2, 1, 10002, '10000000002', '朝阳02', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 3, 1, 10003, '10000000003', '朝阳03', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 4, 1, 10004, '10000000004', '朝阳04', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 5, 1, 10005, '10000000005', '朝阳05', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 6, 1, 10006, '10000000006', '朝阳06', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 7, 1, 10007, '10000000007', '朝阳07', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 8, 1, 10008, '10000000008', '朝阳08', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 9, 1, 10009, '10000000009', '朝阳09', true );
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (10,10, 10010, '10000000010', '朝阳10', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (11,11, 10011, '10000000011', '朝阳11', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (12,12, 10012, '10000000012', '朝阳12', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (13,13, 10013, '10000000013', '朝阳13', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (14,14, 10014, '10000000014', '朝阳14', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (15,15, 10015, '10000000015', '朝阳15', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (16,16, 10016, '10000000016', '朝阳16', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (17,17, 10017, '10000000017', '朝阳17', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (18,18, 10018, '10000000018', '朝阳18', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (19,19, 10019, '10000000019', '朝阳19', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (20,20, 10020, '10000000020', '朝阳20', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (21,21, 10021, '10000000021', '朝阳21', false);
INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '朝阳22', false);
DELETE FROM user_dto;
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (1,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (2,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (3,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (4,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (5,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (6,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (7,1, 2, 3, false);
INSERT INTO user_dto (id, user_id, create_by, update_by, del) VALUES (8,1, 2, 3, false);
DELETE FROM order_t;
INSERT INTO order_t (id, user_id, age, name) VALUES (1, 1, 8, '1,8');
INSERT INTO order_t (id, user_id, age, name) VALUES (2, 2, 7, '2,7');
INSERT INTO order_t (id, user_id, age, name) VALUES (3, 3, 6, '3,6');
INSERT INTO order_t (id, user_id, age, name) VALUES (4, 4, 5, '4,5');
INSERT INTO order_t (id, user_id, age, name) VALUES (5, 5, 4, '5,4');
INSERT INTO order_t (id, user_id, age, name) VALUES (6, 6, 3, '6,3');
INSERT INTO order_t (id, user_id, age, name) VALUES (7, 7, 2, '7,2');
INSERT INTO order_t (id, user_id, age, name) VALUES (8, 8, 1, '8,1');
DELETE FROM user_tenant;
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (1, 1, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (2, 2, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (3, 3, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (4, 4, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (5, 5, 1);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (6, 6, 2);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (7, 7, 2);
INSERT INTO user_tenant (id,user_id, tenant_id) VALUES (8, 8, 2);
DELETE FROM user_tenanta;
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (1, 1, 1, '中文字段1');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (2, 2, 1, '中文字段2');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (3, 3, 1, '中文字段3');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (4, 4, 1, '中文字段4');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (5, 5, 1, '中文字段5');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (6, 6, 2, '中文字段6');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (7, 7, 2, '中文字段7');
INSERT INTO user_tenanta (id,user_id, tenant_id, ) VALUES (8, 8, 2, '中文字段8');

View File

@ -0,0 +1,85 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
DROP TABLE IF EXISTS area;
create table area
(
id int
primary key,
province varchar(255) null,
city varchar(255) null,
area varchar(255) null,
postcode varchar(255) null,
del boolean
);
DROP TABLE IF EXISTS "user";
create table "user"
(
id int
primary key,
"pid" int null,
"name" varchar(255) null,
"json" varchar(255) null,
"address_id" int null,
"address_id2" int null,
sex int null,
head_img varchar(255) null,
create_time timestamp null,
create_by int null,
update_by int null,
del boolean
);
DROP TABLE IF EXISTS address;
create table address
(
id int
primary key,
user_id int null,
area_id int null,
tel varchar(255) null,
address varchar(255) null,
del boolean
);
DROP TABLE IF EXISTS user_dto;
create table user_dto
(
id int
primary key,
user_id int null,
create_by int null,
update_by int null,
del boolean null
);
DROP TABLE IF EXISTS order_t;
create table order_t
(
id int
primary key,
user_id int null,
age int null,
name varchar(255) null
);
DROP TABLE IF EXISTS user_tenant;
create table user_tenant
(
id int
primary key,
user_id int null,
tenant_id int null
);
DROP TABLE IF EXISTS user_tenanta;
create table user_tenanta
(
id int
primary key,
user_id int null,
tenant_id int null,
varchar(255) null
);

View File

@ -5,19 +5,19 @@
DROP TABLE IF EXISTS area; DROP TABLE IF EXISTS area;
create table area create table area
( (
id int auto_increment id int
primary key, primary key,
province varchar(255) null, province varchar(255) null,
city varchar(255) null, city varchar(255) null,
area varchar(255) null, area varchar(255) null,
postcode varchar(255) null, postcode varchar(255) null,
del bit del boolean
); );
DROP TABLE IF EXISTS `user`; DROP TABLE IF EXISTS `user`;
create table `user` create table `user`
( (
id int auto_increment id int
primary key, primary key,
`pid` int null, `pid` int null,
`name` varchar(255) null, `name` varchar(255) null,
@ -29,19 +29,19 @@ create table `user`
create_time datetime null, create_time datetime null,
create_by int null, create_by int null,
update_by int null, update_by int null,
del bit del boolean
); );
DROP TABLE IF EXISTS address; DROP TABLE IF EXISTS address;
create table address create table address
( (
id int auto_increment id int
primary key, primary key,
user_id int null, user_id int null,
area_id int null, area_id int null,
tel varchar(255) null, tel varchar(255) null,
address varchar(255) null, address varchar(255) null,
del bit del boolean
); );
DROP TABLE IF EXISTS user_dto; DROP TABLE IF EXISTS user_dto;
@ -52,13 +52,13 @@ create table user_dto
user_id int null, user_id int null,
create_by int null, create_by int null,
update_by int null, update_by int null,
del bit null del boolean null
); );
DROP TABLE IF EXISTS order_t; DROP TABLE IF EXISTS order_t;
create table order_t create table order_t
( (
id int auto_increment id int
primary key, primary key,
user_id int null, user_id int null,
age int null, age int null,
@ -68,7 +68,7 @@ create table order_t
DROP TABLE IF EXISTS user_tenant; DROP TABLE IF EXISTS user_tenant;
create table user_tenant create table user_tenant
( (
id int auto_increment id int
primary key, primary key,
user_id int null, user_id int null,
tenant_id int null tenant_id int null
@ -77,7 +77,7 @@ create table user_tenant
DROP TABLE IF EXISTS user_tenanta; DROP TABLE IF EXISTS user_tenanta;
create table user_tenanta create table user_tenanta
( (
id int auto_increment id int
primary key, primary key,
user_id int null, user_id int null,
tenant_id int null, tenant_id int null,

View File

@ -1,5 +1,6 @@
package com.github.yulichang.test.join; package com.github.yulichang.test.join;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.MybatisPlusVersion; import com.baomidou.mybatisplus.core.MybatisPlusVersion;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -14,6 +15,7 @@ import com.github.yulichang.test.join.entity.*;
import com.github.yulichang.test.join.mapper.*; import com.github.yulichang.test.join.mapper.*;
import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.Reset;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.test.util.Throw;
import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.DeleteJoinWrapper; import com.github.yulichang.wrapper.DeleteJoinWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
@ -22,7 +24,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.BadSqlGrammarException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
@ -709,12 +710,12 @@ class LambdaWrapperTest {
.select(UserDO::getName) .select(UserDO::getName)
.eq(UserDO::getName, "ref"); .eq(UserDO::getName, "ref");
userMapper.selectList(wrapper); userMapper.selectList(wrapper);
try { Throw.tryDo(() -> {
userMapper.insertBatchSomeColumn(new ArrayList<UserDO>() {{ userMapper.insertBatchSomeColumn(new ArrayList<UserDO>() {{
add(new UserDO()); add(new UserDO());
}}); }});
} catch (BadSqlGrammarException ignored) { });
}
} }
@ -761,10 +762,9 @@ class LambdaWrapperTest {
.selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId) .selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId); .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId);
try { Throw.tryDo(() -> {
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper); List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);
} catch (BadSqlGrammarException ignored) { },DbType.ORACLE);
}
} }
/** /**
@ -818,11 +818,10 @@ class LambdaWrapperTest {
.le(UserDO::getId, 10000) .le(UserDO::getId, 10000)
.orderByDesc(UserDO::getId) .orderByDesc(UserDO::getId)
.setTableName(name -> "bbbbbbb"); .setTableName(name -> "bbbbbbb");
try {
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
} catch (BadSqlGrammarException ignored) {
} Throw.tryDoIgnore(() -> {
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
});
} }
@ -1031,11 +1030,10 @@ class LambdaWrapperTest {
DeleteJoinWrapper<OrderDO> w = JoinWrappers.delete(OrderDO.class) DeleteJoinWrapper<OrderDO> w = JoinWrappers.delete(OrderDO.class)
.leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId) .leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId)
.eq(OrderDO::getId, 1); .eq(OrderDO::getId, 1);
try { Throw.tryDo(() -> {
int i = orderMapper.deleteJoin(w); int i = orderMapper.deleteJoin(w);
} catch (BadSqlGrammarException ignored) { });
//忽略异常 h2不支持连表删除 //忽略异常 h2不支持连表删除
}
//逻辑删除 //逻辑删除
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)"); ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)");
DeleteJoinWrapper<UserDO> wrapper = JoinWrappers.delete(UserDO.class) DeleteJoinWrapper<UserDO> wrapper = JoinWrappers.delete(UserDO.class)
@ -1043,12 +1041,11 @@ class LambdaWrapperTest {
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
.leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId) .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
.eq(OrderDO::getId, 1); .eq(OrderDO::getId, 1);
try { Throw.tryDo(() -> {
DeleteJoinWrapper<UserDO> wrapper1 = new DeleteJoinWrapper<>(UserDO.class); DeleteJoinWrapper<UserDO> wrapper1 = new DeleteJoinWrapper<>(UserDO.class);
int i = userMapper.deleteJoin(wrapper); int i = userMapper.deleteJoin(wrapper);
} catch (BadSqlGrammarException ignored) { });
//忽略异常 h2不支持连表删除 //忽略异常 h2不支持连表删除
}
} }
@Test @Test
@ -1062,22 +1059,22 @@ class LambdaWrapperTest {
.setUpdateEntityAndNull(new AddressDO()) .setUpdateEntityAndNull(new AddressDO())
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
.eq(OrderDO::getId, 1); .eq(OrderDO::getId, 1);
try { System.out.println(update.getSqlSet());
Throw.tryDo(() -> {
int i = userMapper.updateJoin(new UserDO().setUpdateBy(123123), update); int i = userMapper.updateJoin(new UserDO().setUpdateBy(123123), update);
} catch (BadSqlGrammarException ignored) { });
//忽略异常 h2不支持连表删除 //忽略异常 h2不支持连表删除
}
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, " +
"t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, " +
"t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)");
UpdateJoinWrapper<UserDO> up = JoinWrappers.update(UserDO.class) UpdateJoinWrapper<UserDO> up = JoinWrappers.update(UserDO.class)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
.eq(OrderDO::getId, 1); .eq(OrderDO::getId, 1);
try { Throw.tryDo(() -> {
int i = userMapper.updateJoinAndNull(new UserDO(), up); int i = userMapper.updateJoinAndNull(new UserDO(), up);
} catch (BadSqlGrammarException ignored) { });
//忽略异常 h2不支持连表删除
}
} }
/** /**

View File

@ -9,10 +9,10 @@ import com.github.yulichang.test.join.entity.UserTenantDO;
import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.join.mapper.UserMapper;
import com.github.yulichang.test.join.mapper.UserTenantMapper; import com.github.yulichang.test.join.mapper.UserTenantMapper;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.test.util.Throw;
import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.toolkit.JoinWrappers;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.BadSqlGrammarException;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -61,10 +61,10 @@ class QueryWrapperTest {
.setTableName(name -> "fwear") .setTableName(name -> "fwear")
.select("name AS nameName") .select("name AS nameName")
.last("LIMIT 1"); .last("LIMIT 1");
try {
Throw.tryDoIgnore(() -> {
userMapper.selectJoinOne(UserDTO.class, wrapper); userMapper.selectJoinOne(UserDTO.class, wrapper);
} catch (BadSqlGrammarException ignored) { });
}
} }
@Test @Test

View File

@ -1,17 +1,18 @@
package com.github.yulichang.test.join.m; package com.github.yulichang.test.join.m;
import com.baomidou.mybatisplus.annotation.DbType;
import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.AddressDO;
import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.join.mapper.UserMapper;
import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.Reset;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.test.util.Throw;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.github.yulichang.wrapper.segments.Fun; import com.github.yulichang.wrapper.segments.Fun;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.BadSqlGrammarException;
@SpringBootTest @SpringBootTest
public class FuncAliasTest { public class FuncAliasTest {
@ -29,7 +30,7 @@ public class FuncAliasTest {
"t.address_id2, t.del, t.create_by, t.update_by, count(ad.id) AS id, count(addr.id) AS id, " + "t.address_id2, t.del, t.create_by, t.update_by, count(ad.id) AS id, count(addr.id) AS id, " +
"if(ad.user_id < 5, addr.user_id, ad.user_id + 100) AS id FROM `user` t " + "if(ad.user_id < 5, addr.user_id, ad.user_id + 100) AS id FROM `user` t " +
"LEFT JOIN address ad ON (ad.user_id = t.id) LEFT JOIN address addr ON (addr.user_id = t.id) " + "LEFT JOIN address ad ON (ad.user_id = t.id) LEFT JOIN address addr ON (addr.user_id = t.id) " +
"WHERE t.del = false AND ad.del = false AND addr.del = false"); "WHERE t.del = false AND ad.del = false AND addr.del = false GROUP BY t.id");
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>() MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
.selectAll(UserDO.class) .selectAll(UserDO.class)
.selectFunc(() -> "count(%s)", "ad", AddressDO::getId) .selectFunc(() -> "count(%s)", "ad", AddressDO::getId)
@ -39,11 +40,11 @@ public class FuncAliasTest {
Fun.f("addr", AddressDO::getUserId), Fun.f("addr", AddressDO::getUserId),
Fun.f("ad", AddressDO::getUserId)), UserDO::getId) Fun.f("ad", AddressDO::getUserId)), UserDO::getId)
.leftJoin(AddressDO.class, "ad", AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, "ad", AddressDO::getUserId, UserDO::getId)
.leftJoin(AddressDO.class, "addr", AddressDO::getUserId, UserDO::getId); .leftJoin(AddressDO.class, "addr", AddressDO::getUserId, UserDO::getId)
.groupBy(UserDO::getId);
try { Throw.tryDo(() -> {
userMapper.selectJoinList(UserDO.class, wrapper); userMapper.selectJoinList(UserDO.class, wrapper);
} catch (BadSqlGrammarException ignored) { }, DbType.POSTGRE_SQL, DbType.ORACLE);
}
} }
} }

View File

@ -51,13 +51,14 @@ public class TableAliasTest {
"LEFT JOIN address addr2 ON (addr2.id = t.address_id2) " + "LEFT JOIN address addr2 ON (addr2.id = t.address_id2) " +
"LEFT JOIN area area1 ON (area1.id = addr2.area_id) " + "LEFT JOIN area area1 ON (area1.id = addr2.area_id) " +
"WHERE t.del = false AND addr1.del = false AND addr2.del = false AND area1.del = false " + "WHERE t.del = false AND addr1.del = false AND addr2.del = false AND area1.del = false " +
"GROUP BY t.id ORDER BY addr1.id DESC"); "GROUP BY t.id,addr1.id ORDER BY addr1.id DESC");
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class) MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
.selectAll(UserDO.class) .selectAll(UserDO.class)
.leftJoin(AddressDO.class, "addr1", AddressDO::getId, UserDO::getAddressId) .leftJoin(AddressDO.class, "addr1", AddressDO::getId, UserDO::getAddressId)
.leftJoin(AddressDO.class, "addr2", AddressDO::getId, UserDO::getAddressId2) .leftJoin(AddressDO.class, "addr2", AddressDO::getId, UserDO::getAddressId2)
.leftJoin(AreaDO.class, "area1", AreaDO::getId, "addr2", AddressDO::getAreaId) .leftJoin(AreaDO.class, "area1", AreaDO::getId, "addr2", AddressDO::getAreaId)
.groupBy(UserDO::getId) .groupBy(UserDO::getId)
.groupBy("addr1", AddressDO::getId)
.orderByDesc("addr1", AddressDO::getId); .orderByDesc("addr1", AddressDO::getId);
List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper); List<UserDO> dos = userMapper.selectJoinList(UserDO.class, wrapper);

View File

@ -7,13 +7,13 @@ import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.join.mapper.UserMapper;
import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.Reset;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.test.util.Throw;
import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.UpdateJoinWrapper; import com.github.yulichang.wrapper.UpdateJoinWrapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.BadSqlGrammarException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -47,11 +47,10 @@ public class UpdateIncTest {
@Test @Test
void updateInc1() { void updateInc1() {
ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t1.address = t.head_img WHERE t.del = false AND t1.del = false"); ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t1.address = t.head_img WHERE t.del = false AND t1.del = false");
try { Throw.tryDo(() -> {
JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg) JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update(); .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update();
} catch (BadSqlGrammarException ignore) { });
}
JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println); JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println);
} }