This commit is contained in:
yulichang 2022-11-28 09:40:45 +08:00
parent d4a485e3f3
commit 5e9d6b754b
60 changed files with 145 additions and 43 deletions

View File

@ -4,15 +4,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> 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> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.yulichang</groupId> <groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-root</artifactId>
<version>1.3.8</version>
</parent>
<version>1.3.8</version>
<artifactId>mybatis-plus-join-test</artifactId> <artifactId>mybatis-plus-join-test</artifactId>
<packaging>pom</packaging>
<version>1.3.8</version>
<name>mybatis-plus-join-test</name> <name>mybatis-plus-join-test</name>
<modules>
<module>test-join</module>
<module>test-collection</module>
<module>test-mapping</module>
</modules>
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description> <description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
<url>https://github.com/yulichang/mybatis-plus-join</url> <url>https://github.com/yulichang/mybatis-plus-join</url>
<licenses> <licenses>

View File

@ -1,5 +0,0 @@
spring:
sql:
init:
schema-locations: classpath:db/collection/schema.sql
data-locations: classpath:db/collection/data.sql

View File

@ -1,5 +0,0 @@
spring:
sql:
init:
schema-locations: classpath:db/join/schema.sql
data-locations: classpath:db/join/data.sql

View File

@ -1,5 +0,0 @@
spring:
sql:
init:
schema-locations: classpath:db/mapping/schema.sql
data-locations: classpath:db/mapping/data.sql

View File

@ -0,0 +1,20 @@
<?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">
<parent>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-test</artifactId>
<version>1.3.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-collection</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,9 +1,14 @@
package com.github.yulichang.test.collection; package com.github.yulichang.test.collection;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class Application { public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
} }

View File

@ -1,4 +1,8 @@
spring: spring:
sql:
init:
schema-locations: classpath:db/schema.sql
data-locations: classpath:db/data.sql
datasource: datasource:
driver-class-name: org.h2.Driver driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test url: jdbc:h2:mem:test

View File

@ -22,7 +22,7 @@ import java.util.List;
* 移除了mybatis-plus 逻辑删除支持逻辑删除需要在连表查询时自己添加对应的条件 * 移除了mybatis-plus 逻辑删除支持逻辑删除需要在连表查询时自己添加对应的条件
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@SpringBootTest(properties = "spring.profiles.active=collection") @SpringBootTest
class CollectionTest { class CollectionTest {
@Resource @Resource
private TableAMapper tableAMapper; private TableAMapper tableAMapper;
@ -42,7 +42,6 @@ class CollectionTest {
.leftJoin(TableE.class, TableE::getDid, TableD::getId); .leftJoin(TableE.class, TableE::getDid, TableD::getId);
List<TableADTO> dtos = tableAMapper.selectJoinList(TableADTO.class, wrapper); List<TableADTO> dtos = tableAMapper.selectJoinList(TableADTO.class, wrapper);
assert dtos.size() == 1;
System.out.println(dtos); System.out.println(dtos);
} }
} }

View File

@ -0,0 +1,19 @@
<?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">
<parent>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-test</artifactId>
<version>1.3.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-join</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,9 +1,14 @@
package com.github.yulichang.test.join; package com.github.yulichang.test.join;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class Application { public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
} }

View File

@ -0,0 +1,26 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test
username: root
password: test
sql:
init:
schema-locations: classpath:db/schema.sql
data-locations: classpath:db/data.sql
mybatis-plus:
typeEnumsPackage: com.github.yulichang.test
global-config:
db-config:
logic-delete-field: del
logic-delete-value: true
logic-not-delete-value: false
banner: true
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 打印 mybatis plus join banner
mybatis-plus-join:
banner: true
sub-table-logic: true

View File

@ -27,7 +27,7 @@ import java.util.Map;
* 移除了mybatis-plus 逻辑删除支持逻辑删除需要在连表查询时自己添加对应的条件 * 移除了mybatis-plus 逻辑删除支持逻辑删除需要在连表查询时自己添加对应的条件
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@SpringBootTest(properties = "spring.profiles.active=join") @SpringBootTest
class LambdaWrapperTest { class LambdaWrapperTest {
@Resource @Resource
private UserMapper userMapper; private UserMapper userMapper;
@ -40,14 +40,8 @@ class LambdaWrapperTest {
.association(AreaDO.class, AddressDTO::getArea)) .association(AreaDO.class, AddressDTO::getArea))
.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)
.orderByDesc(UserDO::getId) .orderByDesc(UserDO::getId);
.last("unfdjknsnnjkfd");
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper); List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
String s = wrapper.getSqlSegment();
System.out.println(s);
if (list.size() != 1) {
throw new RuntimeException();
}
list.forEach(System.out::println); list.forEach(System.out::println);
} }
@ -63,8 +57,7 @@ class LambdaWrapperTest {
.select(AddressDO::getAddress) .select(AddressDO::getAddress)
.select(AreaDO::getProvince) .select(AreaDO::getProvince)
.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));
.last("unfdjknsnnjkfd"));
iPage.getRecords().forEach(System.out::println); iPage.getRecords().forEach(System.out::println);
} }
@ -85,8 +78,7 @@ class LambdaWrapperTest {
.and(i -> i.eq(UserDO::getHeadImg, "er") .and(i -> i.eq(UserDO::getHeadImg, "er")
.or() .or()
.eq(AddressDO::getUserId, 1)) .eq(AddressDO::getUserId, 1))
.eq(UserDO::getId, 1) .eq(UserDO::getId, 1));
.last("ljfnkegrwbgejkwbenf"));
page.getRecords().forEach(System.out::println); page.getRecords().forEach(System.out::println);
} }
@ -98,8 +90,7 @@ class LambdaWrapperTest {
UserDTO one = userMapper.selectJoinOne(UserDTO.class, MPJWrappers.<UserDO>lambdaJoin() UserDTO one = userMapper.selectJoinOne(UserDTO.class, MPJWrappers.<UserDO>lambdaJoin()
.selectSum(UserDO::getId) .selectSum(UserDO::getId)
.selectMax(UserDO::getId, UserDTO::getHeadImg) .selectMax(UserDO::getId, UserDTO::getHeadImg)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
.last("unfdjknsnnjkfd"));
System.out.println(one); System.out.println(one);
} }
@ -116,8 +107,7 @@ class LambdaWrapperTest {
.select(AddressDO.class, p -> true) .select(AddressDO.class, p -> true)
.select(AddressDO::getAddress) .select(AddressDO::getAddress)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
.eq(UserDO::getId, 1) .eq(UserDO::getId, 1));
.last("unfdjknsnnjkfd"));
page.getRecords().forEach(System.out::println); page.getRecords().forEach(System.out::println);
} }
@ -130,8 +120,7 @@ class LambdaWrapperTest {
List<Map<String, Object>> list = userMapper.selectJoinMaps(MPJWrappers.<UserDO>lambdaJoin() List<Map<String, Object>> list = userMapper.selectJoinMaps(MPJWrappers.<UserDO>lambdaJoin()
.selectAll(UserDO.class) .selectAll(UserDO.class)
.select(AddressDO::getAddress) .select(AddressDO::getAddress)
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
.last("unfdjknsnnjkfd"));
list.forEach(System.out::println); list.forEach(System.out::println);
} }
} }

View File

@ -13,7 +13,7 @@ import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@SpringBootTest(properties = "spring.profiles.active=join") @SpringBootTest
class QueryWrapperTest { class QueryWrapperTest {
@Resource @Resource
private UserMapper userMapper; private UserMapper userMapper;

View File

@ -0,0 +1,20 @@
<?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">
<parent>
<artifactId>mybatis-plus-join-test</artifactId>
<groupId>com.github.yulichang</groupId>
<version>1.3.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-mapping</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,26 @@
spring:
sql:
init:
schema-locations: classpath:db/schema.sql
data-locations: classpath:db/data.sql
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test
username: root
password: test
mybatis-plus:
typeEnumsPackage: com.github.yulichang.test
global-config:
db-config:
logic-delete-field: del
logic-delete-value: true
logic-not-delete-value: false
banner: true
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 打印 mybatis plus join banner
mybatis-plus-join:
banner: true
sub-table-logic: true

View File

@ -12,7 +12,7 @@ import java.util.List;
/** /**
* 注解一对一,一对多查询 * 注解一对一,一对多查询
*/ */
@SpringBootTest(properties = "spring.profiles.active=mapping") @SpringBootTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
class MappingTest { class MappingTest {